How do I warp my player character back to where he started in a level?

The Rigidbody2D script is my only script in the game so far

bool is boolean data type, only 2 values exist, true or false

yeah then try what i said above, change the original_position variable, and set the set_to_respawn() to when it needs to respawn

var original_position=Vector2(498, 252)
var is_set_position:bool=true

Called when the node enters the scene tree for the first time.

func _ready():
original_position=self.position
pass # Replace with function body.

func set_to_respawn():
is_set_position=false

func _integrate_forces(state):
if is_set_position:
return
is_set_position=true
self.position=original_position

func _on_out_of_bounds_body_entered(body):
is_set_position=true
When I go out of bounds it pauses for a split second like it’s going to do something, but it doesn’t.

I also don’t know why my message says in big text “Called when the node enters the scene tree for the first time.”

dont mind that comment, it’s a default comment when creating new script from a node

change to this

func _on_out_of_bounds_body_entered(body):
	set_to_respawn()

Unfortunately it still just hiccups and doesn’t go to start

remove the is_set_position=true
see if it still stuck there

var original_position=Vector2(498, 252)
var is_set_position

Called when the node enters the scene tree for the first time.

func _ready():
original_position=self.position
pass # Replace with function body.

func set_to_respawn():
is_set_position=false

func _integrate_forces(state):
if is_set_position:
return
is_set_position=true
self.position=original_position

func _on_out_of_bounds_body_entered(body):
set_to_respawn()
still doesn’t work :pensive:

if thing doesnt work, then will need to just respawn it the right way, like remove child and queue free current player node/scene, and instantiate new one on the spawn position, which this will need you to have a main controller to control it

1 Like

:melting_face:
I’m sorry but you’ll have to explain this in simpler terms.

will need to create a world where there is platform and player inside
and GUI or UI node to handle the UIs
the world node will have the main controller script, that control spawning of the player and handle platform
the world node with script will recreate player when they out of bound
basically the idea i was saying
so the world has a main script,
the player has their movement script

1 Like

Ok, I think understand the concept, but I haven’t messed around with doing multiple scripts, and stuff yet, so will I need a script for every level, or just a master script that controls how every level starts and restarts

as for levels, it’s recommended to have level generator, but for now making 10 scene of levels will do, and the main script will have the path of these 10 scene, and can be called to instantiate the level scene when needed. the level might no need to have script in it, just positions of things

1 Like

Ok, so how many scripts should I have, and what should they control? And I don’t know how to spawn/unspawn things in Godot.

just 2 for now, main script and player script to control its own movement and interaction

first from main script, remove_child(the_node_or_scene)
then the_node_or_scene.queue_free()

to spawn if you use PackedScene

var new_level=level_scene.instantiate()
add_child(new_level)

note that you can also add_child on a certain path node, not just right where the world node with main script’s direct child. like shown in the example
let’s say you have the level_node as a container or parent to hold the level
then level_node.add_child(new_level), will add the new_level instantiated scene to level_node’s Node
but remember to remove_child from the right parent too, if you did the above with level_node as parent, then it has to be removed from level_node.remove_child(the_current_level), then queue free

What should I attach the main script to, or should it just exist? Idk how to not attach a script to anything, if you even can do that.

creating a script without attaching/instantiating it, will not have the script to function
when you create the world node, right click and select Attach Script option, it would then ask for a name and then just create it. that’s your main script.
the other script will be the one you already have on Player Node

So I should make a new scene with a node called “World”?