- Home /
Question by
MAVRIKO · Aug 30, 2017 at 12:28 AM ·
c#rotationgameobjecttransformquaternion
Auto leveling help
Hi I'm making a fish game and I'm trying to have the fish be able to self right its self over the z axis. Currently my problem is it will lock the z rotation at and it can't be altered without returning to 0 instantly. My goal is to have the fish be able to self right over the z axis over time after being altered. It must also keep its rotation over the x and y axis.
Blockquote
private void Rotate()
{
//calculate rotation
float rotateAroundY = yawLookInput * rotationSpeed * Time.deltaTime;
float rotateAroundX = -pitchLookInput * rotationSpeed * Time.deltaTime;
float rotateAroundZ = Mathf.LerpAngle(transform.rotation.z, 0, .5f);
//rotate
Vector3 rot = transform.eulerAngles;
rot = new Vector3(rotateAroundX + transform.eulerAngles.x, rotateAroundY + transform.eulerAngles.y, rotateAroundZ);
transform.eulerAngles = rot;
//transform.Rotate(rotateAroundX, rotateAroundY, rotateAroundZ);
}
Comment
float rotateAroundZ = $$anonymous$$athf.LerpAngle(transform.rotation.z, 0, .5f);
You don't want the z component of the quaternion rotation, you want euler rotation. Try
float rotateAroundZ = $$anonymous$$athf.LerpAngle(transform.eulerAngles.z, 0, .5f);