![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Godont |
I want to know whether an Area2D
is currently colliding with any part of my TileMap
. By using the body_shape_entered
and body_shape_exited
signals I can detect when some part of the TileMap
has entered or left the Area2D
, but the problem is that receiving the signal that a body shape has exited does not tell me whether all bodies of type TileMap
have exited.
I tried keeping track of the bodies that enter and exit like so:
var colliding_bodies : Array = []
func _on_body_shape_entered(body_rid, body, body_shape_index, local_shape_index):
if body is TileMap:
if !(body_rid in colliding_bodies):
colliding_bodies.append(body_rid)
func _on_body_shape_exited(body_rid, body, body_shape_index, local_shape_index):
if body is TileMap and body_rid in colliding_bodies:
colliding_bodies.erase(body_rid)
if colliding_bodies == []:
# Area is no longer colliding with any tilemap bodies
pass
but the problem here is that the body_rid
is always an invalid RID for TileMap
for some reason.
Is there a simpler way to just know whether an Area2D
is currently colliding with any part of aTileMap
? If I do have to keep track of the bodies that enter and exit, how can I do this given that the RIDs are all invalid?
Thanks!
EDIT
Another odd thing here is that the documentation for Area2D
says that for TileMap
collisions you can
Get the CollisionShape2D node with
body.shape_owner_get_owner(body_shape_index).
However, when I attempt to do this (after confirming body is TileMap
) I get
Invalid call. Nonexistent function ‘shape_owner_get_owner’ in base ‘TileMap’
Am I misunderstanding the documentation here or is the documentation incorrect?
Incidentally, this may be related to this issue (not sure).
Maybe you can just call get_overlapping_bodies()
instead?
exuin | 2023-05-01 20:41