Prevent one building from covering another one

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

Hi!
Currently I am trying to make a building game and fortunately I am able to move one building to other place but now I am stuck. I cannot figure out how can I prevent one building from occupying the position where a building already exists.
EDIT:- My buildings are STATICBODY2D
I am moving my buildings as follow:-

func _process(_delta):
	position = get_global_mouse_position()

Should I use any other way if yes then which and how?

Thank You in advance!

:bust_in_silhouette: Reply From: db0

What are your buildings? Node2D? Control? There’s nothing in Godot stopping you from overlapping as many nodes are you want. You need to supply that logic yourself. If you’re using control nodes it should be easy by using something like a GridContainer. If you’re using Sprites, you’ll need to keep track of each sprite’s rect and ensure no other spire has a point in that rect. But without knowing more of your code, I can’t advise more.

I have edited my question. Please see to it!

And why down vote? is this question really ridiculous?

Help me please | 2021-07-16 07:44

There’s nothing in Godot stopping you from overlapping as many nodes are you want

If it’s like that then why don’t RigidBodies overlap each other and why does KinematicBody collides with Static and Rigid Bodies (on using move_and_slide() or move_and_collide()) and why don’t it overlap them?

You need to supply that logic yourself.

I am not getting the logic that’s why I come up here

Help me please | 2021-07-16 07:50

:bust_in_silhouette: Reply From: Help me please

I got my answer by myself. I m putting it in an answer for those who might need it.

I had created an Autoloaded script and then created an dictionary in it. Each time I had moved my building I updated its position in that dictionary. Before changing any position I first checked if it does NOT occur in the dictionary. If it does not occur there then I updated the position