- Home /
Rotation along the x-axis to that player can turn around?
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);
}
Answer by Commander5518 · Aug 30, 2014 at 05:55 AM
Import your Standard Assests. Use the 3rd person controller. Switch out the construction worker for your sphere. It has a mouse control script with it. Your script is not very well organized so it is kind of difficult to tell what you are trying to move with. Sorry if I' way off
No need for apologies. Im new to coding so I need the criticism. I changed my coding. I hope its more understandable. Reading your comments are you saying that I need to import my components again? Is your advice based you not understanding my coding? I want the players to use the $$anonymous$$eyboard and not the mouse to control the main piece.