Checkpoint for items like boxes,items

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

So basically I Have a checkpoint for the player where when he dies he goes to that “flag” in this case but I want the rest of the items to stay in the last position and not make tp to the flag here’s the code in the flag:

extends Area2D
    func _on_Bandeira_body_entered(body):
    	CheckPoint.last_position = global_position

And this in the level node:

extends Node2D


func _enter_tree():
	if CheckPoint.last_position:
		$Player.global_position = CheckPoint.last_position

Edited: I forgot to mention but the code for the items to teleport its not done yet I am just asking if someone knows how to do it

Does the scene reload when the player dies?

do you have this code?
get_tree().reload_current_scene()

ramazan | 2022-07-13 10:27

yes I do that in the player

Tolozed | 2022-07-13 11:17

:bust_in_silhouette: Reply From: USBashka

I don’t see any code that teleports items other than $Player, but it seems like you forgot to check if entered body is player, so other object will trigger checkpoint too. Try this:

func _on_Bandeira_body_entered(body):
    if body.name == "Player":
        CheckPoint.last_position = global_position

If items teleports to the checkpoint, maybe you have code somewhere else. You can also paste restarting code to the Player’s _ready function so it won’t affect anything else

Oh I am sorry I didn’t explain correctly
This code teleports the player as it should but if I add items to it will teleport them to the flag, for example, if I get the checkpoint and I die the trampoline goes to the checkpoint too I only want the player to teleport to the flag and the rest stay in the last position
So my question is how can I only teleport the player but the rest stays in the last position

Tolozed | 2022-07-13 10:31

Did you add items as player’s childs? All childs coordinates attached to parent. If not, I don’t know, what the reason is, sorry

USBashka | 2022-07-13 11:09

I didn’t put the code for the items yet for now it only teleports the player to the checkpoint and the rest it’s in the same level as the begging of the level
Now I want once he gets to the flag the player position goes to the flag he dies he goes to the flag but how could I add to the code so when the player gets to the flag the rest of the items stay where they are instead of teleport to the flag like the player

Tolozed | 2022-07-13 11:24