deadinside
deadinside

Reputation: 23

Check if any body overlaps with Area2D

I am trying to check if a KinematicBody2D enters an Area2D. There is a signal for that(on_body_entered), but it only emits when the body is completely inside the area. Is there a way to constantly get if a body is just overlaping?

Upvotes: 0

Views: 2936

Answers (1)

Theraot
Theraot

Reputation: 40295

but it only emits when the body is completely inside the area

This is not correct. A more accurate description of the "body_entered" would be that it triggers on contact. The body could be partially or totally overlapping.

I suggest you enable "Visible Collision Shapes" from the debug menu. Perhaps your collider are not set the way you expect them to be.

We do not have a signal for when the body is completely inside.


What you can do is set up a smaller area (or a larger one depending on your need)…

The idea is to have two areas that are one larger than the other, in such way that there is a margin for just the size of the player character, then when the outer one triggers, it means the character is only overlapping the larger one, and when the inner one triggers the character is fully inside the larger one.

For example, if you have a 500 by 500 area, and your player is 100 by 100, then set an area with the size 300 by 300 centered at the larger area… When the player enters in contact with the smaller area, it will trigger the "body_entered" signal, which will also mean it is entirely inside the larger one. If you only got "body_entered" from the outer area but the inner area, then the player character is overlapping the outer area, but not fully inside it.

Upvotes: 2

Related Questions