The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

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!

Godot version v3.2.3-stable_win64
in Engine by (942 points)
edited by

2 Answers

+1 vote
Best answer

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

by (942 points)
–1 vote

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.

by (115 points)

I have edited my question. Please see to it!

And why down vote? is this question really ridiculous?

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

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 Frequently asked questions and 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 [email protected] with your username.