- Home /
This question was
closed Aug 22, 2014 at 06:45 AM by
HexadimensionalerAlp for the following reason:
Found Solution
Question by
HexadimensionalerAlp · Jul 14, 2014 at 03:37 PM ·
c#player movement3rd person camera
3rd Person Controller How to make the player face camera lookdirection [C#]
I want my player to rotate to the direction I'm looking at when I press W or S. I tried nearly all solutions I found at UnityAnswers and other websites. With the following code I made the player rotate but he didn't stop rotating after he was at the desired rotation:
public float rotateSpeed = 4.0f;
public GameObject Player;
public GameObject Cam;
if (controller.isGrounded && Input.GetKey(KeyCode.W)) {
moveDirection = forward;
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
float CamRot = Cam.transform.rotation.y;
float desRot = CamRot * rotateSpeed;
Quaternion target = Quaternion.Euler(0, desRot, 0);
Player.transform.Rotate(0, desRot, 0, 0);
}
Comment
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Making a bubble level (not a game but work tool) 1 Answer
Why isn't my character moving down? 3 Answers
How can I make the player step forward on mouse click? 2 Answers