how can I make a sensor in unity ?,how can I make a distance sensor in unity ?,
So I would like to make a sensor in unity to get th distance between the sensor and the nearest obstacle.
I know the function to get the distance between two object but it gets it between the center of these two objects and not to the nearest surface in a straight line.
Is there a build in function to do that ?
and if not how would you do it ?
thanks for the time it took you to answer :),
Comment
Answer by Dragate · Dec 07, 2017 at 08:05 AM
Instead of finding the distance between the position of those 2 objects, you can first raycast from sensor to obstacle and then, get the distance between sensor position and hit.point of raycast.
Your answer
![](https://koobas.hobune.stream/wayback/20220612144138im_/https://answers.unity.com/themes/thub/images/avi.jpg)