How to make a camera orbit a planet and always look towards a player in the world while maintaining the player's forward vector at the top of the camera?
My current idea to use a camera attached to a spring arm, attached to the world, this maintains the correct position for the camera, but the rotation of the camera towards the player is wrong. If any one has a clue on how I could use an easier technique on getting a camera to orbit the cube planet (directly above the player), while the player is constantly moving, and to have the player's forward vector pointing towards the top of the camera's point of view, please do share.
I have tried placing a camera on the player, but then the world isn't centered to the camera, unlike the photos below. By placing the camera behind the character, it does achieve the right rotation that is desired. I have also tried a free floating camera, unattached to either the planet or the character, and was able to achieve this by extending a vector from the center of the world (0,0,0) towards the player, and extended it further out till the radius of desired range of the camera. This worked the same as below, but it also ran into the same problem with camera rotation.
The answer depends on what is the most important for you. Setting it on the planet allows for always looking at the planet and you have to constantly update the position of the camera such that the planet location, player location and camera location are on a line. You can do this by getting a vector from the planet to the player, normalize and multiply it using a scalar value that is your radius. You also have to set the rotation like you are doing above.
The other option is to attach it to the pawn and add the offset rotation between the vector from the planet to the player and the current spring arm vector.
The former uses your code and allows for more customization of your camera location and rotation, but it will always focus the planet. The latter allows you to easily change focus around which you want to rotate or focus.
The code complexity is about the same.
answered Aug 05 '16 at 09:01 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here