I am working on my first unity project and and am new to unity and programming in general. My first project is going to be a tower defense type of game. I am working on a grid system to decide what is a buildable space and what is not on any terrain I create without having to manually tweak the grid squares. Below is my first attempt which acutally works fairly well but I can think there is a better way. I dont want to create 2500+ objects if I dont have to for obvious reasons.
The way this grid works is I have a plane as a square. I get the size of the terrain and set the amount of rows and columns I specify then loop through to create the grid and it will calculate the square size based on terrain size and rows/columns. On the grid square prefab I have a script that will destroy itself if it collides with the terrain.
Instead of actually instantiating the planes for the grid I can just put the positions of each grid square in an array. The problem with that is I will have active positions on the slopes of the hills which I do not want. The other problem I have is with my grid system I cannot use the highpoints. If there was a plateau I would like to place towers on they would destroy thier selves because they are higher then the ground level. I did search google and the forums but I could not find anything to tackle this specific problem.
I can post code if necessary but I think its pretty self explanitory even for a begginer like my self. Any advice, theory or just general conversation on this I would greatly appreciate.
even though he says it should be self explanatory, i dont get it.
Why would you want to place towers somewhere just to let them destroy themselves (dont place them there in the first place) ?
And what do you mean by ‘highpoint’ ( place-able area looks plane to me) ?
This is likely for a “Tower-Defense” style game, judging the setup thus far.
Maybe you could make a raycast on multiple sections on the same ‘square’ and check the max difference over the y-axis within the same square?
(I.e. scanning each square on all corners and the middle, checking if the lowest and highest value in y have a smaller difference then a specific treshold, or using normaldirection to judge how slanted the square is?)