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 want to trigger a function when an object crosses the border of the level. So I used a StaticBody2D with a CollisionPolygon2D, with trigger set to true.
enter image description here
According to the documentation:
A trigger polygon detects collisions, but is otherwise unaffected by physics.
But, how do I trigger a function when an object crosses it?

enter image description here
I tried to connect a signal to the StaticBody2D but there is no "body_enter" signal...
I can detect the collision from all kinds of objects instead (ugh), but then, what is the trigger property for?

in Engine by (29,360 points)

I think the problem is the staticbody2D with "body_enter" signal

1 Answer

+1 vote

The name of that property is chosen pretty badly. A more fitting name would be "disable solver", since the "trigger"-setting doesn't turn the collision shape into a trigger, it simply disables the collider except for triggering purposes.

That means that if you have an Area2D it will report any physics bodies passing through it not matter whether they have the trigger flag set or not. When it comes to collisions between physics bodies though collision shapes with the trigger flag set will not cause any.
So the trigger flag allows you to turn off collisions without making an object invisible to Area2Ds.

by (1,124 points)

So, how can I use the level border as a trigger? Area2D doesn't fits my needs because it's rectangular, border is made of segments. If possible, I don't want to modify the script of all types of objects that can go through.

The Area2D node works just like the PhysicsBody nodes, the shape is defined by an attached PhysicsShape. So the Area2D is not rectangular unless you attach a PhysicsShape2D with a new RectangleShape.

Ok, I'm a bit stupid because I already did that for pickups in my game :'D

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.