Ok I am working on a 3D project where my player piece is navigating through a maze. I can’t make it rotate on the X axis. It can move left and right but it does not turn. So the view is only straight forward. My Code is below. You can see in my comments i am trying everything. Please Help!
#pragma strict
var speed : float = 2;
var distToGround: float;
var centerOfMass : Transform;
var cam : Transform;
function Start()
{
// get the distance to ground
distToGround = collider.bounds.extents.y;
}
function IsGrounded(): boolean
{
return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1);
}
function FixedUpdate ()
{
//THe directions the player peice will go based the keyboard arrows
var moveHorizontal : float= Input.GetAxis ("Horizontal");
var moveVertical : float= Input.GetAxis ("Vertical");
var movement : Vector3 = new Vector3 (moveHorizontal,0.0f,moveVertical);
// When the player peice turns left or right, it tilts slightly
rigidbody.rotation = Quaternion.Euler (0.0f, rigidbody.velocity.x, 0.0f);
// The acceleration for the player peice
var XYVelocity = rigidbody.velocity;
rigidbody.velocity = movement * speed;
// The Camera is following the player peice
rigidbody.AddForce (transform.rotation * cam.transform.forward * moveVertical);
rigidbody.AddForce (transform.rotation * cam.transform.right * moveHorizontal);
}