Question by
kaspertandrup5 · Dec 07, 2020 at 09:48 AM ·
rotationrotate objectthird-person
Rotate player in camera direction
I'm working on a third person game and I'm having trouble rotating my player in the direction the camera is facing. the problem is that the player does not rotate but keeps facing the same diraction. The code I have can be seen below:
float moveHorizontal = Input.GetAxisRaw("Horizontal");
float moveVertical = Input.GetAxisRaw("Vertical");
player.cameraYRotation = Camera.main.transform.eulerAngles.y;
Debug.Log("Camera Rotation: " + player.cameraYRotation);
Vector3 rotation = new Vector3(0.0f, player.cameraYRotation, 0.0f);
Vector3 movement = new Vector3(moveHorizontal * player.speed, 0f, moveVertical * player.speed);
player.transform.localRotation = Quaternion.Slerp(player.transform.rotation, Quaternion.LookRotation(rotation), 0.1f);
player.playerRigidbody.transform.position += movement * Time.deltaTime;
Any help will be appreciated.
Comment
Your answer
Follow this Question
Related Questions
Making Weapon look at middle of the screen 0 Answers
Rotation issue 0 Answers
rotate an object with HTC Vive controller 0 Answers
Character Rotation 0 Answers
My rotation is not the same in inspector as it is in the scirpt 0 Answers