Developer postOriginal post (opens in a new tab)

The Laser Rangefinder

While I'm currently hard at work to polish a demo for JOY OF PROGRAMMING for the upcoming Steam Next Fest, I'd like to introduce another machine you can work with in the game. The laser rangefinder. This device can measure the distance between itself and some target you point it to.

In real-life this nifty piece of technology works by sending out a laser pulse in a narrow beam (like a laser pointer) towards a target and then measuring how long it takes for the reflection of this laser pulse to return to the rangefinder. In the game this can be simulated quite cheaply by sending out a singe line trace from the rangefinder and stopping at the first blocking hit. While measuring distance is very useful in many situations, the in-game rangefinder is turning out to be a multi-purpose sensor than can also read tags attached to the target, like their type, name, etc, the physical size of the target, its current speed or its mass.

Using the rangefinder in Python code is quite straight forward. Like all entities in JOY OF PROGRAMMING it uses an object-oriented interface. So first you need a reference to one of the rangefinders currently in the game. You can find them either by their respective name or by using the "first" function, if there is only one. Then you call one of the member functions to retrieve information about the target, like its distance to the rangefinder.

rf = RangeFinder.first()
print(rf.get_distance())

Happy Coding!