- Home /
Create squares and draw them on terrain
Some of you've might played Clash of Clans or Simpsons tapped out? I'm not trying to make a game like them, but they have one feature I like. They're grid system. I'm familiar with the math around squares and grids, a * a = b(square). So that's no problem for me. My real problem is how I would transfer this into unity. Say I'd like the squares to be 3 units times 3 units, which makes 9 units in area. How do I create this in Unity and loop it over the terrain? This would be good to know, because I need to create a grid system for my game, but as I said, the game is not going to be as any of those examples, it's just an idea how the grid would be. Any examples, tutorials or just logic is appreciated, I just want to get moving with this. Also, I prefer code.
Thanks!
How complicated is your terrain? If it's flat, then you could start experimenting by writing a 2d loop that creates a bunch of tiled planes.
Screenshots, images or links are helpful to describe what you are attempting.
It all depends on if you want a cursor that moves around the terrain while snapping its position to a grid, or if you want to texture the whole terrain as a grid.
Basic snapping formula : http://answers.unity3d.com/questions/325293/script-place-blockprefab-align-to-grid-like-$$anonymous$$ecr.html
This link is more advanced, and only some parts may be relevant. Try video 5 : http://www.youtube.com/playlist?list=PLbghT7$$anonymous$$mckI4qGA0Wm_TZS8LVrqS47I9R
Even more advanced would be editing the splatmap of the terrain to texture it as a grid.
Hi, and thank you for your answers. $$anonymous$$y terrain is flat, but I'd rather use code to be honest. I made an image as suggested by @alucardj
Basically, the grid will be used to instantiate objects and will also be used for combat and AI systems. As I said, I prefer code guidance :)
This tutorial may be useful, specifically the video on placement (3b) : http://cgcookie.com/unity/cgc-courses/unity-tower-defense-course/
Answer by flaviusxvii · Oct 22, 2013 at 04:57 PM
Make a camera. Position it at -10, -10, -10. Have it look at 0, 0, 0.
Now make some Planes. Texture them with grass and stuff. Duplicate and place as many as you need for your game map.
Now make a script called TerrainTile, or something like that. Give it an OnMouseDown() function. Now you can handle mouse clicks and stuff. Put that script on all of your planes.
Good start?
That's a good start, but I'd prefer code. But thanks anyways, but this is totally a solution if I don't make it with code :)
Not that different in code. $$anonymous$$ake a tile prefab. Use Instantiate to make a bunch of them in a loop.
Your answer
Follow this Question
Related Questions
How would I replicate Gizmos.DrawLine in-game? 1 Answer
Terrain Brush Problem 2 Answers
How to draw an outline over a shape composed of many squares in a square grid? 1 Answer
Transparent grid shows odd irregularities when displayed. 1 Answer
Creating a terrain of tiles from an dimensional array 1 Answer