- Home /
Movement based on rotation
I am trying to make a very simple videogame with a car. But i don't know how can i move based on the rotation...
This is my code...
using UnityEngine; using System.Collections;
public class Car : MonoBehaviour { Animator anim; Vector3 moveDirection; // Use this for initialization void Start () { anim = GetComponent(); }
// Update is called once per frame
void Update () {
moveDirection = this.transform.position;
Vector3 = Input.GetAxis ("Rotation");
if (Input.GetKey (KeyCode.RightArrow)) {
transform.Rotate (0, 0.5f, 0);
}
else if (Input.GetKey (KeyCode.LeftArrow)){
transform.Rotate(0, -0.5f, 0);
}
if(Input.GetKey(KeyCode.UpArrow)){
moveDirection.z += 0.2f;
}
else if(Input.GetKey(KeyCode.DownArrow)){
moveDirection.z -= 0.2f;
}
this.transform.position = moveDirection;
}
}
Thank you so much.
Comment
I've changed your question title - please read the FAQ or watch the video before posting.