I'm attempted to create a third person camera which will rotate around the player as I move the mouse left and right. I've worked out a right vector to move the camera along by which should change as the camera rotates to look at the player's position which it'll do constantly

void PlayerCamera::RotateAroundPlayer()
    XMVECTOR cameraEye = XMLoadFloat4(&Eye);
    XMVECTOR cameraUp = XMLoadFloat4(&Up);
    XMVECTOR atPlayerPos = XMLoadFloat4(&this->playerPos);

    XMVECTOR playerDirection = XMVector3Normalize(atPlayerPos - cameraEye);
    XMVECTOR cameraRight = XMVector3Cross(playerDirection, 

    cameraEye += camYaw * cameraRight;

    XMStoreFloat4(&Eye, cameraEye);

The issue I'm now having is making sure the camera stays at a fixed distance away from the player (like a normal third person camera would) while still being able to rotate around the player. The rotation will override whatever I do to keep the camera's position at a fixed distance away so I'm kinda stumped on what to do at this point. The camera's X and Z positions need to update along with the player's X and Z positions so that it stays following the player but can still rotate around the player

I'd love some help if anyone can provide

  • \$\begingroup\$ You may find this OrbitCamera .h/.cpp a useful reference. Creating good third-person game cameras is definitely an art so best of luck! \$\endgroup\$ – Chuck Walbourn Dec 21 '18 at 17:29

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.