# How to get the height of a tower made out of blocks?

So I’m making this sort of a 3D tetris game where the main point is to create as tall towers as possible. The data I need from the towers is the height and position. At the point of the tower the tower creates an influence radius, where the player is able to place more blocks. At the moment I have my game board where players drop pieces and I have two different block prefabs at the moment. Straight line block with one box collider childed to it and L-block with 2 box colliders respectively.

Now the problem is I can’t figure out how to get the height of a tower. And I need to be able to get the bottom blocks position to get the point where the tower is. The tower height should be the absolute highest point measured in a 90 degree angle from the bottom block to the tip of the tower.

So here the middle tower should be the highest. and the third one should be a bit higher than the first one as the block is a bit diagonally and reaches higher. Block count does not affect the outcome. Only the height.

Should I do something with some sort of child structure? So that every time you stack a block it goes in to a tower hierarchy?
Or maybe try to get a height map and locate the tower from that?

I really don’t know how I would do either of those, but those solutions sound somehow logical maybe… I would be really glad if someone atleast points me to the right direction. Almost forgot: I use C# for my scripts if that matters to you all.

Let’s consider a scenario.

I have a box of x = 5, y = 1, z is not relevant to our issue.
If I use collider.bounds.extent I get (2.5f,0.5f,z) since those are half of the size.
I could also simply store the values in a script.

I am about to give you a solution but you could maybe optimize it and mostly this is for one object, you still to figure it out over the whole game:

Here we go.

1. Get the vertices of the model

2. Convert vertices to world position

3. Find the highest y value of the vertices

4. Use projection to find the vector from the highest point to the ground

5. Get the distance with magnitude.

``````Vector3 [] vertices;
Vector3[] _meshPos;

void Start(){
Mesh mesh = GetComponent<MeshFilter>().mesh;
vertices = mesh.vertices;   // 1
_meshPos = new Vector3[vertices.Length];
}

public void Update(){
// 2
for(int i = 0; i< vertices.Length;i++){
_meshPos _= transform.TransformPoint(vertices*);*_
``````

* }*
//3
* Vector3 highest = FindHighestPoint(meshPos);
_
// 4*

* Vector3 projection = Vector3.Project( -highest, Vector3.down);*
// 5
* float distance = projection.magnitude;*
* print (distance);*
* }*

* public Vector3 FindHighestPoint (Vector3[] arr)*
* {*
* Vector3 highest = Vector3.zero;*
* float y = 0;*
* foreach (Vector3 vec in arr)*
* { *
* if(vec.y > y){*

* y = vec.y;*
* highest = vec;*
* }*
* }*
* return highest;*
* }*