- Home /
Look Where You're Going
I have a player that can walk around in a 3d space. The Player is just a Capsule, with a regular Capuse Collider. The controls are simple so far.
var dir = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
transform.Translate(dir*Time.deltaTime*10);
The problem is I need the player to look where its going. I've tried LookAt(dir)
, I've transform.Rotate(0, hor+dir,0)
but both get me really strange rotations. I've even tried
var rot = Quaternion.Euler(dir);
transform.rotation = Quaternion.Slerp(transform.rotation, rot, Time.deltaTime);
But that doesn't do anything.
Can you help me?
Answer by easilyBaffled · Jan 06, 2013 at 11:08 PM
Thanks for trying guys, but I found this solution http://answers.unity3d.com/questions/28109/how-to-turn-and-face-the-direction-im-moving-using.html. I wasn't planning on using the CharacterController but it seems to be the smart thing to do at the moment.
Answer by KazeEnji · Jan 06, 2013 at 10:11 PM
Have you tried making the camera a child of the capsule? That should turn the camera when you turn the capsule.
The Camera is not attached to the Player its floating overhead
Answer by Piflik · Jan 06, 2013 at 10:35 PM
Try this:
transform.forward = Quaternion.Slerp(transform.forward, dir, 0.1f);
Unfortunatly no that didn't work either, also you want Vector3.Slerp if it did.