How to rotate the camera around an object? [3D]

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Alex Pires


I want to make the camera rotate around the player, like the moon does with the earth, always focusing the player, but I have absolute no idea how to implement this. All I can do is make the camera turn around it’s own axis. I tried to make depth translations along with rotation_degrees, but this looks terribly wrong. Is there a way to transfer the axis of rotation to the player?

*Sorry about my english.

:bust_in_silhouette: Reply From: kidscancode

Probably the easiest way to do this is to add a Spatial to the player and make the Camera a child. Offset the camera by your desired distance and then just rotate the Spatial. Because of the node relationship, the Spatial will move with the player, and the Camera will move with the Spatial.

    Spatial <- rotate this one

It’s a creative solution, but when you make use of Spatial rotation may lead to a huge performance consumption. I will figure out another way of doing this, I’m making various tests with Path, but seems to be very complicated since the children of the Pathfollow don’t suffer modifications along the way, and this is very complicated to deal with it. Probably I will go back to my original idea and layout. Thank you for the answer!

Alex Pires | 2019-02-24 18:18

What makes you think rotating a Spatial node has any impact on performance?

kidscancode | 2019-02-24 19:09

I’m new to Godot, but as far I know Spatial It’s the parent of all 3D nodes. I’m comparing with the act of importing libraries, if you don’t be specific you’re loading things you won’t use. As the name says : Spatial, you’re rotating the reality around the spoon like Neo did in Matrix.

: )

Alex Pires | 2019-02-24 19:57

This is not correct at all. Spatial is not “the parent of all 3D nodes”. On the contrary, it’s the simplest of 3D nodes. It has a small number of properties related to position and orientation in space, and that’s it:

What you may be confused by is that all 3D nodes inherit from Spatial. All 3D nodes have Spatial properties. That means a Camera is a Spatial node, a KinematicBody is a Spatial node, etc. This is how Godot is designed to work. You’re going to need to use 3D nodes if you’re going to do things in 3D.

I highly recommend going through the official tutorials, in particular:

  • Step by Step - introduces the editor, node hierarchy, and overall “Godot way” of doing things
  • 3D Section - several good tutorials here, including working with 3D nodes and building an FPS game

On another note, when you’re a beginner worrying about performance is the very last thing you should be doing. Make something, then worry about whether there’s a performance issue if there turns out to be one. Odds are, especially with the very small projects you’ll be doing as a beginner, there’s not going to ever be one.

kidscancode | 2019-02-24 20:09

It works and it’s great ! Thanks for your answer.

Subzero8 | 2019-11-05 02:22


is there also a way of doing that without making the camera a child? My camera script is based on the car-game tutorial of Bastiaan Olij (and I have been extending on it). Making the camera a child of the Spatial (and thus from the car), I get an error because of this bit:

func _ready():
    follow_this = get_node(follow_this_path)
    last_lookat = follow_this.global_transform.origin

I want to be able to look around the car with the right stick (so bringing the right stick down would also enable to look behind.

I’m also fairly new to Godot and game creation in general and it’s not always easy to find the information (that you actually need). There is general information (docs) and then there is specific information to specific problems of others.

eyeEmotion | 2020-04-11 17:51