This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

So basically I'm making a platformer and I want the player to respawn at a certain place when it touches an area 2d under the lava.

in Engine by (25 points)

1 Answer

0 votes
Best answer

There are things called signals in Godot. Areas and bodies have built in signals "onareaentered" "onbodyentered", they trigger the moment other physical object crosses borders of their collision shape. You want to connect those signals to a node of choice and implement respawning under this signal.

by (8,188 points)
selected by

hey! I can't figure out how to change the location when the onbodyentered is triggered
enter image description here

Just override global_position to coordinates of your choice.

global_position = Vector2( something, something )

It's simple just add a line of Code like this

func _on_Lava_area_entered(area):
    if area.is_in_group("Enemy"):
        $Player.position.x = "Position X"
        $Player.position.y = "Position Y"

Where it says "Position X" goes the position.x you want, the same in "Position Y" but with the position.y what you want

Or you can add a Position2d in the position you want

func _on_Lava_area_entered(area):
    if area.is_in_group("Enemy"):
        $Player.position =  $Position2d.position

Hey! um it still isn't working enter image description here

You need to learn how to read errors. Print screen is too small to see, but I am sure error says, that invalid type has been asserted onto float value. position is of type Vector2, and it consists of two type floats - x and y. You tried to change them into type String - which is indicated by "" or yellow color in editor. Enter numbers, without "".

And don't use position, use global_position !!

Oh sorry if you did not understand me but ah the positions should not be put in quotes.

This is the real code

$player.position.x = 104
$player.position.y = 528


Hey! I had already tried that out but didn't work but no problem instead of changing the position I'm making the scene reload whenever it touches the bottom of the lava

ok, but if you checked the comment about $ position2d? that works% 100

Or you can add a Position2d in the position you want

func _on_Lava_area_entered(area):
    if area.is_in_group("Enemy"):
        $Player.position =  $Position2d.position
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.