0 votes

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?

asked Aug 25, 2019 in Engine by Abhishek_98 (21 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

0 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:
    Camera.position=player.position

If that helps, please mark this answer as best.

answered Aug 25, 2019 by johnygames (1,558 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 How to use this Q&A? before posting your first questions.