Checking collisions with RigidBody2D nodes that are frozen

Godot Version



I’m creating a tetris-style game using RigidBody2D nodes for each item in the scene. I have it set up so that each node is placed one at a time using the mouse to move and the spacebar to place. But when placing a new node, I’m trying to set it up so that you can’t place the node where one currently is.

To check for collisions before placing a node, I set up my code so that each RigidBody2D stores its position and size inside a Rect2. I then use a new Rect2 to check for intersects when moving a new item around. If an intersect is detected, then I block the movement.

I’ve been having a ton of trouble with this though, as some of the nodes work perfect if they’re the same size, but nodes that aren’t the same size don’t seem to detect their boundaries at all, and end up letting you move them inside other placed nodes.

Is there a smarter way to handle this (i.e. not using Rect2s)? Or is what I’m doing the right track to go down? For additional context, I’m freezing the RigidBody2D nodes when they’re moved around with mouse input, and sleeping them once they’re placed in the scene and before the next object is spawned.

I’m pretty new to coding, and about 2 months into using Godot, so apologies for any vagueness or bad descriptions!