+2 votes

Hi!

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.

in Engine by (91 points)

1 Answer

+2 votes

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.

Player
    Spatial <- rotate this one
        Camera
by (21,940 points)

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!

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

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.

: )

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:

https://docs.godotengine.org/en/latest/classes/class_spatial.html

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.

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

Hi,

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.