Return Area3D at the given coordinates

Godot Version

4.3.1

Question

Is there a simple and easy way, better if does not involve instanciating collision checkers or using signals, to get which Area3D is instanciated at some specific coordinates?
I have a few 3D areas (each with its CollisionShape3D) spread at some random coordinates.
Is it possible to write a method that given the coordinates return the Area3D at those coordinates, if present?

this would be the method structure:
func get_area(coords: Vector3) -> Area3D

You could use a dictionary to store each area by its position and then check if the dictionary contains this position.

Not sure, but I guess you could make the dictionary static inside your area script and then make each area set itself up in the dictionary.

1 Like

I have a few 3D areas (each with its CollisionShape3D) spread at some random coordinates.

this basically means they exist inside the SceneTree.
These 3d areas are either instanced inside a common node-container or are assigned a group. Either way, you can loop through them and then check if the Vector3 coords is inside its collision. Return the 3d area if that is the case.

1 Like