- Home /
Question by
Miziziziz · Sep 06, 2014 at 06:30 PM ·
rotationquaternion
rotations smooth in scene view but not game view
I have a gun turret that rotates to face the player. What's happening is that the gun barrel is 'skipping' if I have it turn too fast. This doesn't happen when viewed through the scene view, though. Only from the FPS controller camera.
code:
public float maxRotateSpeed = 40f;
public float minTimeToReach = 0.5f;
public Transform turretFrame;
public Transform turretGun;
Transform _cameraTransform;
float _velocity;
float _velocityGun;
public Transform target;
void Update ()
{
Vector3 newRotation = Quaternion.LookRotation(target.position - turretFrame.position).eulerAngles;
Vector3 angles = turretFrame.rotation.eulerAngles;
turretFrame.rotation = Quaternion.Euler(angles.x,Mathf.SmoothDampAngle(angles.y, newRotation.y, ref _velocity, minTimeToReach, maxRotateSpeed),angles.z);
Vector3 gunAngles = turretGun.rotation.eulerAngles;
turretGun.localRotation = Quaternion.Euler (Mathf.SmoothDampAngle(gunAngles.x, newRotation.x, ref _velocityGun, minTimeToReach, maxRotateSpeed), turretFrame.rotation.y,turretFrame.rotation.z);
}
this is what my scene looks like (the gun part is a child of the frame part):
example.png
(127.4 kB)
Comment
Your answer
Follow this Question
Related Questions
Reverse local rotation applied to child 1 Answer
Particle System Instantiate's With Original Rotation - C# 1 Answer
Basic quaternion question 1 Answer
Child versus Parent rotations 3 Answers