r/howdidtheycodeit • u/Mumbolian • Oct 15 '22
Area placement buildings - dragging a road, or houses etc
Hi everyone, i understand how to place individual buildings using a coordinate system, but I’m lost on how to enable a player to drag build a road or a group of 30 houses in a game like Caesar for example.
Could anyone share some light, I’ve not been able to find resources on this issue?
Thanks
21
Upvotes
6
u/robbertzzz1 Oct 15 '22
What you're looking for is a grid placement system. Games where you can build typically have a square grid that all object are placed on. Roads will be made up of lots of separate tiles that all chain together to make a road, and because they use the same grid as buildings they'll all fit together perfectly. There should be plenty of tutorials on the subject.
2
u/moonshineTheleocat Oct 15 '22
Depends on the complexity. Is this something closer to Cities Skylines? Or something else? You'll want to provide a video or picture of what you want
2
u/NUTTA_BUSTAH Oct 16 '22
I've seen multiple devlogs on YouTube that have tackled this issue. I'd suggest looking for those resources. Maybe search for "city builder dev log". Should outline the common pitfalls and solutions. It gets complex with more and more rules for different placements and bigger and bigger worlds requiring optimization hacks.
If you could specify a bit better, I could maybe give a clear answer but I have not made such a system myself, but I have done procedurally generated minigolf for example.
1
u/Wschmidth Oct 16 '22
Caeser is done on a grid of tiles, so it's easy enough. While holding the mouse button, check the tile nearest the cursor and see if it's occupied, if it's not: place a road. If you're placing houses it's the same thing, but you'll check the surrounding tiles as well.
Games like City Skylines which (I think) aren't on a grid are a bit harder but not actually by that much. If placing houses you can check an invisible cube collider near the cursor instead of a tile. If placing roads, you can create a spline between the position you started holding down the mouse button and the current mouse position, if there's any collision between those two positions it means you can't place the road. Spline are cool, they morph sprites/models to follow a path.
1
u/squall2014 Nov 13 '22
Here is a series that you can watch to get an idea:
https://www.youtube.com/playlist?list=PLcRSafycjWFd6YOvRE3GQqURFpIxZpErI