- Home /
Measure a rotating gameobject.
This is a cube. Sometimes it is a square. Sometimes a triangle. It is under a random multi axis rotation. How under these circumstances can I measure it?
The green box is the bound's box. It always holds the maximum measurement for the game object, therefore cannot be used to accurately measure the actual size of the object.
Say that I wanted to slide this object to one direction, one unit of itself. along its own transform.right axis how can I make it find its own width along this axis? (think a sliding door or window, just at a random angle (therefore disqualifying the easy bounds measuring))
I know how to move the object along this axis. I just can't tell the object how far to accurately move itself under constraint of a random rotation.
I hope this makes sense.
Well the only way I can think of us to get the mesh renderer or mesh filter of the object and check the bounds of the mesh, you can do position + bounds.extents.x/2 to get either side of the object and same for every other vector to get each bound of the axis, but if you're talking surface to surface then you'd need to do a bit more calculations, but I imagine you could just move outwards from center on the local axis then use the nearest point function on the bounds to get the outside face of local normal, then do the same for the other side and you have you local axis bounds.