Checking for collisions using shapes returns no values?

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

Hello, y’all,

I have a 3D game with a 2D map the player can drag and select units RTS-style. This map is contained within a Control node, since it’s part of the HUD/UI, and I’ve already written several scripts to detect the collisions within the selection rectangle, each time running into a different problem…

Right now I’m using this method:

public void CheckForCollisions(Rect2 rectangle)
{
    var parameters = new Physics2DShapeQueryParameters();
    var rectShape = new RectangleShape2D();
    
    rectShape.Extents = rectangle.Size * 0.5f;
    parameters.SetShape(rectShape);
    parameters.Transform = new Transform2D(0, rectangle.Position + (rectangle.Size * 0.5f));


    var results = GetWorld2d().DirectSpaceState.IntersectShape(parameters);
    GD.Print(results);

    tempRect.Size = rectShape.Extents * 2;
    tempRect.Position = parameters.Transform.origin - rectShape.Extents;
}

This method is called within _PhysicsProcess() and its “rectangle” parameter is the selection rectangle drawn within the _Input() function. All is good, except it won’t detect any collisions at all, even though the map is filled with Kinematic Bodies and their corresponding CollisionShape2D’s.

I’ve even tried:

  • moving these bodies around, and they do collide with each other, so the issue has to be somewhere else;
  • placing other bodies on different places of the hierarchy, to no avail;
  • placing the function above on different places of the hierarchy, pointlessly;
  • using a simpler Rect2.Intersects() pipeline, but I ran into local x global coordinates hell and burned and died and now I’m a ghost forever doomed to wander this lonesome earth aimlessly.

What could possibly be causing this issue?

Btw, you guys can check the full code on GitHub, if you really want to.

Thanks in advance!