Just started using unity, and i’m a avarage programmer. I came up with this project of a tower defense, and i’ve already surpased some problems. But now i really got stuck.
What i want to do is: make some kind of plane that acts like a grid, witch everytime i click to buy a tower it highliths the squares i can build towers.
I’ve asked arround and people says i will need a grid. Well, i’ve imagined that it would be a grid, but have no clue on HOW to actually build it, and represents it in positions on a script.
Anyone who already have worked with grids could post any help, links or tutorials, about building grids and working with it? I’ve already searched it here, but people don’t say HOW TO DO IT, just that it must be done with it.
From the top of my head, how about initializing a grid made of several planes?
If you need a grid of 20x20 with size 5, just instanciate planes of size 5 inside a for cycle, then in each plane just detect if the mouse is over it.
Might not be the best method, i just came up with this 8)
A grid isn’t really rocket science though, just think of it as a 2D array. Keep in mind that your graphical representation isn’t part of your logic. Just make some sort of connection between a grid tile and some model.
Sorry if it’s the wrong section, didn’t pay attention when created it.
Well, my problem is to build this grid, once i build it, i know that i will somehow keep my project going. But i have no clue on how to divide a plane so that equal squares on it will be recognized as diferent spaces. What i really need is an example on any project that used something like this so i could see it implemented, and would understand how it works.
What i’m not being able to see is the grid itself, i have ideas on how to use it, but i don’t know how to actually create one.
I understand that the idea of several planes would work, but i have to pass it, since i want to learn the other way.
The easiest way to go about it is likely to have a source mesh… and then define how “big” you want a tile in terms of its X and Y and then generate a grid based on the mesh.
The grid doesn’t have to be a physical “thing”, each tile can just be a “section” of the actual mesh you are working against.
So if you have a mesh that is 10 x 10, and you define your tile size as 5 x 5, then you can calculate a 2 x 2 grid that will span your input mesh.
When you click on your parent mesh, you can have a script calculate the position that you clicked, and interpret which “tile” that click belongs to, and render whatever effects appropriately. I would guess this is how Tempest is rigging up his really cool Griddy system. You may want to talk with him about how he accomplished what he did, I doubt he’ll give you sourcecode because I believe he’s planning on selling his system, but he may give some sagely advice.
Things get a little fuzzy though when your input mesh doesn’t divide evenly against your tile size… but this can be dealt with either by ignoring areas that do not define a “whole” tile, or you can perhaps calculate a buffer zone that would define an area that does divide evenly. That can be dealt with when the hurdle comes up though.
Good luck! If you have any progress, do keep posting. I will be doing a system similar to this as well for an upcoming project of mine. If I’m able to rig up something simple I may post as well. Just not sure when I’ll be free to work on it… school is driving me nuts
As for Tempest, they are the author working on the Griddy project (aka they’ve already accomplished some of the goals you are looking to accomplish to they will likely have some advice)… check the post here: http://forum.unity3d.com/viewtopic.php?t=53449
That is their Griddy project preview post. So far it’s looking really great.