- Home /
Solution found.
Issue with my camera controls
I've been working on a 3rd person camera controller. Basically, it is always located behind the player (with an offset) and is not a child. Unfortunately, the camera seems to be circling around the player, resulting being over the player's right shoulder at 0 degrees and over the left shoulder at 180 degrees. But staying at the back of the player works fine.
Heres the code :
rotationX -= Input.GetAxis("Mouse Y") * cameraRotateSpeed * 0.02f;
rotationX = Mathf.Clamp(rotationX, -45, 65);
rotationY += Input.GetAxis("Mouse X") * cameraRotateSpeed * 0.02f;
Quaternion rotation = Quaternion.Euler(rotationX, rotationY, 0);
Vector3 targetPos = transform.position + new Vector3 (0.3f, 1.65f, 0.1f);
Vector3 direction = rotation * -Vector3.forward;
camera.transform.rotation = rotation;
camera.transform.position = targetPos + direction * cameraZoom;
How can i make it stay over the right shoulder of the player? I know I'm missing something, maybe something stupid. :P
Thanks for the help!
One line I'm confused about... The targetPos is generated from it's own transform? Shouldn't that be something like:
Vector3 targetPos = Target.transform.position + new Vector3 (0.3f, 1.65f, 0.1f);
Can you show the hierarchy view for these objects?
The player and the camera are two seperated objects. They are not parented. But the script controlling the camera is on the player with the rest of the movements.
As for the target, transform.position is the player's position.
Now that I think about it, I think the problem is linked with the offset (+ new Vector3 (0.3f, 1.65f, 0.1f)). It will have to be changed depending on the player's rotation. How could I do that?
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
WASD Movement with Mouse position dictating which way the character is facing 1 Answer
Camera Follow works partially, need help to finish the script 3 Answers
I only rotated X, but Y and Z are shifting as well when I play the game. 1 Answer
How do I limit my chracters rotation on the X axis? 1 Answer