Can someone please help me out? thank you in advance!
So I've got a camera that goes along a track, always following and always looking at the player (kinda like little nightmares). I use the camera's right and forward (ignoring the camera's y) to set the direction vector for the player's y rotation axis. I'm assuming there's nothing wrong so far, but now the problem is that I want the up vector to be the normal in which the player is standing on, the code bellow almost works for pointing the player y towards the normal, it's fine for rotating the z axis of the player, but it doesn't work for the x axis
void RotatePlayer()
{
forward = mainCamera.transform.forward * verticalAxisInput;
right = mainCamera.transform.right * horizontalAxisInput;
walkVector = forward + right;
newPosition = new Vector3(walkVector.x, 0.0f, walkVector.z);
player.transform.rotation = Quaternion.LookRotation(newPosition, normal.normalized);
rb.MovePosition (rb.position + player.transform.forward * velocity * Time.deltaTime);
}
Your answer
Follow this Question
Related Questions
Rotation in wrong direction 0 Answers
Rotate a dial and stay at end-position 0 Answers
Applying multiple rotations 1 Answer
rotating with Euler Angles causes bug when bellow 0° 0 Answers
Having two objects Y axis parallel rotating around local Z axis. 0 Answers