My game involves a plane, controlled using input.acceleration for the iPhone, that moves left and right to avoid buildings. Moving the plane is not an issue, however when i add the code to make it tilt, the plane starts to move down on the y-axis. I have no idea what’s going on. This problem does not occur without the code to tilt. Any and all help would be much appreciated! My code is as follows:
Vector3 dir = Vector3.zero;
dir.x = Input.acceleration.x;
if (dir.sqrMagnitude > 1)
{
dir.Normalize ();
}
dir = dir * Time.deltaTime;
transform.Translate(dir * speed);
//this part is the code i add to tilt the plane i.e. where the error occurs
Vector3 movement = new Vector3 (dir.x, 0.0f, 0.0f);
rigidbody.velocity = movement * speed;
rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
All variables, such as tilt and speed, have been previously initialized as public variables and are manipulated in the game controller. Thanks again for the help!