Godot Version
V4.3 mono
Question
Hi everyone,
I’m currently working on a game project in Godot using C#, and I’m facing some challenges with structuring the collision detection for items.
The player in my game has an Area, which I use to detect collisions with other objects, and this works fine. In the player’s script (player.cs), I check if the player can pick up an item by calling the GetOverlappingBodies()
method on the Area object. Then I check the type of the overlapping bodies to determine if it’s an item that can be picked up.
Each item in my game is currently a StaticBody3D with a CollisionShape3D as a child object to define its collision shape. Additionally, each item has its own Area3D with a CollisionShape3D so that it can detect collisions with other objects, as the item itself should know when it collides with something in the world.
Now, my question is whether this dual collision detection setup (using both StaticBody3D and Area3D) is redundant. The player’s Area detects collisions with items (StaticBody3D), but for the item I can’t simply check for events from itself (StaticBody3D) with other StaticBodies.
The item itself also needs an Area3D so that I can listen for events:
public override void _Ready()
{
AreaForCheckingDeploymentCollisions.BodyEntered += OnBodyEntered;
AreaForCheckingDeploymentCollisions.BodyExited += OnBodyExited;
}
private void OnBodyEntered(Node3D body)
{
if (body is StaticBody3D && body != this)
OverlappingStatics.Add(body);
}
private void OnBodyExited(Node3D body)
{
if (body is StaticBody3D && body != this)
OverlappingStatics.Remove(body);
}
This feels inefficient, and I’d like to unify the approach.
Additionally, I’m not sure if using StaticBody3D for items is the best choice, especially since I’m manually moving and positioning the items in code (the coordinates are directly set). I’ve seen that other node types can be used in a “static” mode.
So here are my questions:
Is it a good idea to unify the collision detection setup (using both StaticBody3D and Area3D)? How can I achieve a cleaner structure?
Thanks in advance for your help and advice!