0 votes

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!

Godot version 3.2.3 - mono
in Engine by (35 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.