Orbit camera for third person controller

I want to have a camera that can orbit around the player with the mouse while the player is moving, while also limiting the maximum angle it can rotate to.

Also, how do I get the player to change its direction when the camera rotates? I want to rotate the player smoothly when pressing different keys.

Link to my project: https://playcanvas.com/project/972107/overview/advanced-character-controller

And to make it clear, I do not want links to the tutorials. I’ve tried them out and their results are not what I desire.

Thanks in advance

Hi @SayHiToMePls,

From what I see your example does have the camera orbit while the player is moving.

On how to limit the camera you will need to clamp the maximum rotation values you apply. Since you don’t want example links, I won’t share :innocent: (hint: model viewer starter kit, the orbit camera applies min/max rotation angles).

For rotating the player to match the camera rotation you can use the pc.Vec3.lerp method. One way to do it is to implement a smooth lookAt method, try searching around in the forums for similar topics.

Hope that helps.

2 Likes

Since you don’t want example links, I won’t share :innocent: (hint: model viewer starter kit, the orbit camera applies min/max rotation angles).

:face_with_hand_over_mouth:

And how do I make the camera follow the player because when I tried the tutorial version, it stayed at its original position. You could see the camera shaking, when starting to move, but it always tries to keep its original position.