Hello is there a way to detect if an static body overlaps with other static bodies?
I want to check if a space is already occupied before i spawn the static body.
Add an Area2d as a child which will work on a separate 2d layer to detect the collisions
But an area cant detect static bodys to my knowledge
I assume you have a node with a script that spawns the static bodies.
In that script, you will have to have a physicsprocess function which will check for the Area2D of each static body with getoverlappingareas() or getoverlappingbodies()
If the value is not empty then it overlaps with an area and you will have to move or remove it programmatically
I made a TemplateStaticBody as follows:
| -> Sprite
| -> Area2D
| -> CollisionShape2D (For area2d detection)
| -> CollisionShape2D (For static body)
Then I made two inherited scenes one BlackPawn and one WhitePawn.
Created a Node2D scene (World) and added them inside overlapping each other. Then made a script to that World, and did the following:
This did not show any overlapping areas.
Then, did a physicsprocess call:
Which proves that there are overlapping bodies. I tried to yield one idle frame in ready() but it didn't produce the overlapping either, so it needs a minimum threshold of time to detect the overlapping areas that _physicsprocess does.