How do I stop camera2D from following the character while it's falling?

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

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 :slight_smile:

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?

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

Schweini | 2019-08-25 14:54

:bust_in_silhouette: Reply From: johnygames

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.