finding the distance to a point in the terrain


I am trying to implement a laser distance sensor similar to those commonly found on commercial robotic platforms.

I started off with a variation of the roaming ralph example, using a collision ray to detect obstacles around the robot.

The collision ray, is working (graphically) as expected, the collision of the ray with the closest point in the surface is marked with a red blob. However I can’t figure out how to get the distance between my robot and the red blob. I am aware of the getDistance method on Actors, but my problem is to find the exact object to which I am supposed to get the distance.

the screenshot below illustrates the problem: You can see a ray coming from the front of the robot and colliding with the ground at a point marked by a red blob

can anyone help me here?

At the point where the ray collides, you can retrieve the distance between your object and the collision point by doing:

1 Like