- Home /
Plane Control Script rotating unexpectedly
Hello, all. I was wondering if there was a way to fix this script so that the plane does not rotate at all along the z axis. All help is appreciated. here is my code:
var moveSpeed : float;
var rotateSpeed : float;
function Update ()
{
var h : float = Input.GetAxis("Horizontal");
var v : float = Input.GetAxis("Vertical");
transform.Rotate(Vector3(v*Time.deltaTime*rotateSpeed, h*Time.deltaTime*rotateSpeed, 0), Space.World);
transform.rotation.z = 0;
transform.Translate(transform.forward*Time.deltaTime*moveSpeed);
}
Comment
Best Answer
Answer by aldonaletto · May 27, 2011 at 02:11 AM
Don't mess with transform.rotation! It's a Quaternion, a strange creature with four dimensions (x,y,z,w), where z is not the z axis as we humans know it. I did the same mistake and it almost drove me crazy. You can set transform.eulerAngles.z (which is expressed in degrees) to 0 instead, but this can produce rounding errors after some time. Do you really need to zero the z axis?