How to use the 'trigger' property on CollisionPolygon2D?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Zylann
:warning: Old Version Published before Godot 3 was released.

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?

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?

I think the problem is the staticbody2D with “body_enter” signal

puppetmaster- | 2016-06-20 08:13

:bust_in_silhouette: Reply From: Warlaan

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.

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.

Zylann | 2016-06-20 12:43

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.

Warlaan | 2016-06-20 13:23

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

Zylann | 2016-06-20 14:21