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

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?

Godot version 3.4
in Engine by (12 points)

1 Answer

+1 vote

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.

by (22,674 points)

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!

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 shapeownerget_owner in base TileMap. Any ideas on what I'm doing wrong?

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.