+1 vote

Hi, I am new to Godot and I am trying to make a basic 2D action game. I have learnt some basics of level designing and creating character animations and tbh I am enjoying it a lot :)

Now the problem arises once I attach a camera2D node to my player node. The camera keeps following the character (which is what I want), but it even follows it while it's falling. I have searched every youtube tutorial about this problem, but I couldn't find anything. Can anyone please help me?

in Engine by (22 points)

A camera2D always follows it's parent, but you could detect when the player's falling and set the cameras current property to false. I dunno how you could do this cuz I don't know how your game looks

1 Answer

+2 votes

Do not have the camera follow the player by setting it as a parent. Instead, make a script that copies the player's position property and then have the camera update its own position based on that. That way you can offset the camera to any value you want on any given axis and you can also stop updating its position whenever something happens.

In your case you should copy the camera's position every frame in the func _physics_process(). Create a variable named var falling and set it to false by default. When the player's position is lower than some value in the y axis (or any other custom logic you have for recognizing falling), then set the falling variable to true. The camera should then update its position only as long as the falling variable is set to false:

if falling==false:

If that helps, please mark this answer as best.

by (1,867 points)
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 webmaster@godotengine.org with your username.