Question by
kirito015 · Dec 05, 2017 at 10:41 AM ·
gameobjectraycastscript.
How can i get the height of an object
The problem is that i'm using a raycast to detect when the player is in fron of a step of a stair but i don't know how to get the height of each step i know that i can use the collider of the step to get the height but this way doesn't work for me because the stair is a model that i exported from blender Can someone help me I'm sorry that my english isn't like yours
Comment
Answer by PizzaPie · Dec 05, 2017 at 03:09 PM
The easiest way would be to place a primitive collider over each step and pick up its bounds to find the height. Not optimum but quite easy.
float GetStepHeight()
{
RaycastHit hit;
if(Raycast (...,out hit,...){
if(hit.collider.tag == "Step") //some way to check if it is a step or use name or make use of Layer masks and remove this
return hit.collider.bounds.size.y;
return -1; //some default value in case the raycast does not hit a step collider
}
PS: Render.Bounds will give the bounds of the whole model not a single step.