Question by
jacob10012004 · Jan 27, 2017 at 10:19 PM ·
rotationmovement
Get player to look in movement direction?
Hello. I am trying to get my player to look in the direction of it's movement. I have searched this up and I cannot find it anywhere. Here is the code for the movement :
if(Input.GetKey("w")) {
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
if(Input.GetKey("s")) {
transform.Translate(Vector3.back * speed * Time.deltaTime);
}
if(Input.GetKey("a")) {
transform.Translate(Vector3(-speed * Time.deltaTime,0,0));
}
if(Input.GetKey("d")) {
transform.Translate(Vector3(speed * Time.deltaTime,0,0));
}
Thanks!
Comment
//this might help?
//Put A Character Controller on this component. You will find it in Phisics
public float speed = 6.0F;
private Vector3 moveDirection = Vector3.zero;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
CharacterController controller = GetComponent<CharacterController>();
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
controller.$$anonymous$$ove(moveDirection * speed * Time.deltaTime);
}
Your answer
Follow this Question
Related Questions
How to return original rotation of object 0 Answers
Record and replay movement 0 Answers
Look Left or right but keep walking forward 0 Answers
moving an object continuously between waypoints 0 Answers
How can I see what line of my code is moving my object? 2 Answers