The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I'm trying to make a platformer about a snake running around and making difficult jumps and if you fail them you die. I tried using a single Area2D node for the ground so that if you fall you die and change scene this is the code:

func onArea2Dbodyentered(body):
gettree().changescene("res://Death Screen.tscn")

it's connected through an onbodyentered Signal.
I tried putting 2 of them in a single scene but it automatically changes to the death screen even when the player is not touching any of the 2. Can someone help me?

Godot version 3.3.2 stable
in Engine by (14 points)

1 Answer

0 votes
func onArea2Dbodyentered(body):

Is called then any PhysicsBody2D enters Area2d

So it goes like this.
1. Your platforms are StaticBody2D
2. One of them barely touches Area2D
3. Death screen

Use Collision layers and masks or check body parameter in if statement. (Collision layers is better, with if Area2D still calls function on every collision)

by (887 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.