Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | throwaway47 |
Camera rotation in third-person is not a problem, it just comes down to a simple .look_at(player)
, and moving the camera around in a first-person shooter is easy as you simply steal the player’s coordinates. However, camera movement in a third person game is tricky.
For example, in RuneScape, you are in third-person, and you can move your camera around your player using arrow keys. For instance, if you hold the left arrow key, your player will stay in the dead center, but your camera view will be circling around your player in a clockwise manner. The left/right keys can always move in a full circle around your player. In this process, the x and z values change but the y value remains fixed.
If you use the up/down keys, this same circular movement will happen, but in the up/down direction, in that if your player was facing the camera view, your view would circle around the player’s front and back, going under surface each time in the process. Of course, this would only happen if the up/down movement is unrestricted, which is not the case in RuneScape. This would likely be a simple min() and max() to prevent the camera from going beneath the surface, or too high up. This type of movement will alter x, y and z values.
This type of system can be thought of as a sphere of available camera positions, where the camera is a point traveling along the edge of the sphere, and the center point of the sphere is the player’s position. The radius of the sphere is the distance between the player and the camera. Of course, one could do all the spherical math like this Godot user did to determine how to move the camera around, but it’s very messy.
Surely there is a much better way to do this with Godot transforms? The answer by MysterGM to the above question alludes to the use of transforms to solve this problem, but doesn’t provide any examples.
In summary: how do you use Godot transforms to move your camera like in RuneScape?