Need Tips or Help with a Factorio style grid building system

Godot Version

4.5.1

Question

So ive been trying to make a game kinda like factorio because its my fav game right now. I’ve gotten to the point of having a global script to hold functions to add, get, and erase nodes registered to a dictionary, and to the point of having objects with different sizes, like 1x1 and 2x2. The one part I can never get right is having rotatable objects, like with a 2x1 object, for example, which never works when rotated. If anyone has done this type of thing before, plz help.

If you’re sharing code, please do so as text between 3 backticks (`) and it’ll format as code.

As for your rotating issue, are the scenes you’re rotated at the center? Seems like they’re off center so when rotating they also move.

I tried making some code so I put that photo to show problems I have. I’m mainly asking if anyone else has done stuff like this, what was their method, because I can’t find anything online

I understand, but for sharing code, it’s easier if you wrap it in 3 backticks (`) like this:

```
print(“Hello world”)
```
So it’ll show up like this:

print("Hello world")

Which makes it a lot easier for you to get the help you need. Also, the screenshot of the code you shared doesn’t seem to have anything to do with the rotation.

Are all the tiles in your game separate scenes? That’s what I assumed, hence the comment about perhaps the scene not being in the center. If they aren’t could you share the full code, and elaborate how you rotated this one?

Factorio is a big game!

Anyway, when you are rotating your object, it seems like the pivot point is not at the centre of your object. You can fix that by setting it to the centre before rotating it, if it is a control node you can use set_pivot_offset combined with get_size() / 2 or if not make sure your scene is centered or use set_centered(true)

Centered for a sprite

Pivot offset for a control node

Objects have a pivot_point that controls what point they rotate around. You probably want to set it to half their size.