0 votes

Pretty simple - maybe. I have a camera (current) that follows the player, but I also have a main viewport that is in a static position to the world and contains some UI elements.

When my player dies (queuefree) I create a popup. However, since the camera is a child of the player, I can't display this popup in the same position that the player died (because the player viewport is gone when the player is queuefree() ).

So, how do get my camera to stay at the player's position upon player death (queue_free())?

I assume a better way to go about this is to get the main "world" viewport that is currently static to follow my player instead of having the player's camera child at all, but all the tutorials I've seen only have the camera as a child of the player, and I've looked and looked.

Any ideas on how to solve this dilemma?

in Engine by (24 points)

1 Answer

0 votes

It is pretty tricky to make a camera follow that isn't a child. The documentation starts to go into it if you look up camera2D in the docs.

My first question would be, why queue_free() right when he "dies"? Why not just make him invisible and stop taking input? that is probably the best option. Then after the popup you queue_free().

You could also try re-parenting the camera node:

Camera2D.global_position = global_position

I use this code to re-parent particle effect trails on projectiles after they explode. I am only worried about the global_position part in this case because idk if the Camera2D will work with that.

lmk if you need any further help!

by (597 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 [email protected] with your username.