- Home /
Question by
AHsaber · Oct 14, 2014 at 12:05 PM ·
rotationcamera rotatelookrotationfacing
How to get an object to face in the direction that it is traveling?
In my new project I was hoping to allow the player to move freely as the camera is able to rotate around him. While trying to set up my third person camera I came to a standstill seeing as my Player would not look in the direction that it is traveling.
if (Input.GetKey (KeyCode.W)) {
transform.Translate(camPivot.transform.forward * movementSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.S)) {
transform.Translate(camPivot.transform.forward * -1 * movementSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.A)) {
transform.Translate(camPivot.transform.right * -1 * movementSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.D)) {
transform.Translate(camPivot.transform.right * movementSpeed * Time.deltaTime);
}
If anyone could help me I'd really appreciate it! Been stuck for 2 days on this T~T
Comment
Answer by SaraCecilia · Oct 14, 2014 at 09:06 AM
Perhaps you could try TransformDirection? http://docs.unity3d.com/ScriptReference/Transform.TransformDirection.html. There are some examples of how to use it in a thread here: http://answers.unity3d.com/questions/154176/transformtransformpoint-vs-transformdirection.html