How to detect CollisionShape2D at a given global position?

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

I’m trying to implement a system for avoiding spawn and teleport collision. Is there a function that allows me to “look” at a global position and get a list of all the CollisionShape2D overlayed in that position?

I’d like to look at those position ahead of time to determine whether to teleport my player there or the move on to the next position.

I’m currently using has_overlapping_areas() but it’s not working very well because it requires me to teleport my player to the position in order to check the area.

:bust_in_silhouette: Reply From: spaceyjase

Yes, you could use ray-casting from the spawn position:

Alternatively, you could use a ShapeCast node (doc) and check is_colliding when you want to spawn, or even define an Area with appropriate signals to verify if the spawn point is clear.

How you implement is up to you and your game’s requirements.