- Home /
Question by
Hurnkey · Mar 31, 2018 at 06:00 AM ·
c#movementthird person controller
When rotating my player's head it gets all jumbled up.
Hello I am trying to make a game where you are a robot and its a third person game so I want my robots head and the camera to turn when I click the appropriate arrow keys. Here is my code:
public float Speed = 50;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey ("up")) {
transform.Rotate (Vector3.right * Speed * Time.deltaTime, Space.World);
}
if (Input.GetKey ("down")) {
transform.Rotate (Vector3.left * Speed *Time.deltaTime, Space.World);
}
if (Input.GetKey ("left")) {
transform.Rotate (Vector3.up * Speed *Time.deltaTime, Space.World);
}
if (Input.GetKey ("right")) {
transform.Rotate (Vector3.down * Speed * Time.deltaTime, Space.World);
}
}
But when my robot turns his head to the left/right and then click the up arrow key his head gets all out of whack. Any help, sorry if this is confusing I am just starting.
Comment