Find all collision areas in rect (2d)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By gorrgorr

Hi! I’m trying to implement a custom field-of-view method inside a rect. To do this, I want to find all collision objects in a certain collision layer that intersects my rect. Some of these (but not all) are a part of a tilemap.

What’s a good (preferrably pretty fast) way to find all collision objects that are intersecting a rect?

:bust_in_silhouette: Reply From: jgodfrey

Instead of a Rect2D, why not define your area via an Area2D node, which already provides the ability to detect overlaps with other collision shapes. The details might vary based on your setup, but I’d guess a quick read through the Area2D usage page might be all you need to get on track.

Sounds like a good fit for what I’m doing :). Still a little unclear on how the signals work and how to get individual collision shapes from a tilemap though, but I’ll read up on it. Thanks!

gorrgorr | 2022-04-15 09:21

Been playing around with this for a bit and found the following:
body_shape_entered(body_rid: RID, body: Node, body_shape_index: int, local_shape_index: int). The docs are saying

body_shape_index the index of the Shape2D of the PhysicsBody2D or TileMap used by the Physics2DServer. Get the CollisionShape2D node with body.shape_owner_get_owner(body_shape_index).

This sounds exactly like what I’m trying to do, but when calling this i get an error: Nonexistent function shape_owner_get_owner in base TileMap. Any ideas on what I’m doing wrong?

gorrgorr | 2022-04-15 12:05