Advertisement

How would I begin learning to build a sim based grid in Unity? (examples included)

Started by October 12, 2017 11:46 PM
1 comment, last by frob 7 years, 1 month ago

Hello. If this topic is in the wrong section, I apologize. Mods, please move it so I know the appropriate category to put these questions in in the future. Or recommend better category to post questions like this one in so I'll know for next time.

 

I would like to experiment with building a sim type game. Can someone point me toward a resource that might help me understand how to lay out squares then allow the user to freely construct walls? Nothing beyond that for now, just an interface that places strait mono colored walls on a grid. 

 

4.thumb.jpg.9b906f1a78e15f42feb54f14d786c434.jpg

maxresdefault.thumb.jpg.6fe7c5eeb91c2b1a3e6ad25552656c49.jpg

 

This is my placeholder signature

Those are not easy games to build, and the Unity engine is not designed to work like that out of the box.

Unity allows creation of arbitrary objects, and allows you to build and clone your own objects through a system of what they call "prefab" objects. Unity normally works with freeform placement, so all the work of creating wall-type objects, and the work of snapping objects to a regular grid, keeping that grid on the ground, and any other placement rules such as not interfering with other object's footprints would all be handled through your own game code.

I don't know of any specific versions, but I imagine the Unity store has several libraries that people have written for that type of thing. A few quick searches using Google show many tutorials and demos of working with grids generally, but I don't see any that cover exactly what you are looking for.

If you can find one of those as an existing tool on the store, that may save you some work.  You will probably need to modify it, tweak it around a bit, but it can give you a start.

 

As for what to learn if you intend to work like that,  the first thing you'll need is how to work with the math of the grid world.  If you aren't already comfortable with it, a grid can be put together fairly easy using modulus math (the % operator), but working at odd scales irregular placement outside the grid can be more tricky. 

Creating objects will mean understanding how to work with prefabs.  You'll want to read up on tutorials for creating prefabs and spawning prefabs through code. There are lots of tutorials on that.

As you'll want them on the ground layer, you'll want to find some tutorials about working with the ground. Many of the prefab tutorials have notes about using a raycast to find the height of the ground and then placing it at that height.  It can have trouble if your ground is not flat, so learning to modify your height grid programatically should be on your list if ground is not flat.  You'll note in the first two incarnations of The Sims players were forced to build a ground slab before placing walls.

After that, from your description you'll need to learn about rubber band selection or rectangle area selection so you can pick the items based on your mouse areas while playing in game. Again, there seem to be plenty of tutorials on that.

And assuming you want all this to happen in game as part of an in-game editor saving the world designs (rather than in the Unity editor where you modify your program's structure) you'll need to learn all about serialization or save/load systems.

If you are going for something like The Sims, that game does a tremendous amount of work to hide the differences between the logical world in data and the visual world that you see.  Game objects in logic are merged together. Many things are hidden in various ways. For example, you can only see inside the buildings on your lot, and only the height level you are currently on. When it comes to rendering many objects have their models and textures fused together so that instead of rendering hundreds of tiny decorations the game actually renders a few large irregularly-shaped objects. You generally don't see it as a player, and as a developer it is typically not seen unless working in the code directly related to editing the sims or editing the snap-together items in the world, such as countertops and walls.

I hope that gives you some options for places to look.

This topic is closed to new replies.

Advertisement