Welcome to the forums @Tractic!
There are several different ways to handle checkpoints, but here is what I have found as the easiest way:
Have an Area2D node (with a CollisionShape2D) that covers where you want your checkpoint to be. Make sure to make it big enough that the player cannot easily avoid the collision shape if they walk by the checkpoint.
In the Area2D, connect the body_entered
signal to a function. In this function, check to see if the body that has entered is the player. If it is, then add something like player.checkpoint_position = global_position
.
In your player script, add var checkpoint_position = null
to your class variables. This variable will store the position of the last passed checkpoint, and the checkpoint will set this position when the player has passed (as seen in the step above).
Then, when the player has entered the fall zone, move the player to the stored checkpoint_position
variable IF it does not equal null
. Something like:
if (body.get_name() == “Player”):
print(“Player has fell into fall zone!”)
if (body.checkpoint_position != null):
body.global_position = body.checkpoint_position
And that should do it! It is a super simple way of handling it, and I would suggest making some changes if you plan to use this method going forward (like making the respawning at a checkpoint a function of the player that the fall zone calls), but hopefully this helps give you a bit of an idea on one way that checkpoints can be achieved.
Also:
This discussion was caught in the moderation queue since you have not confirmed your account yet.
Upon creating your account you should have received an account verification email. The confirmation email may have been incorrectly flagged as spam, so please also check your spam filter. Without confirming your account, future posts may also be caught in the moderation queue. You can resend a confirmation email when you log into your account if you cannot find the first verification email.
If you need any help, please let us know! You can find ways to contact forum staff on the Contact page. Thanks! :smile: