LIDAR#

Warning

Deprecated. The LIDAR service will be removed in a future release. Use SpaceCenter.raycast_distance() instead.

Provides functionality to interact with the LiDAR mod.

LiDAR Replacement#

A LiDAR casts a fan of rays from its part. SpaceCenter.raycast_distance() casts one ray. This example casts 8 rays below the root part of the active vessel:

import math

import krpc

conn = krpc.connect(name="Raycast Example")
sc = conn.space_center
part = sc.active_vessel.parts.root
frame = part.reference_frame

# A fan of 8 rays below the part, 10 degrees apart
origin = (0.0, 0.0, 0.0)
directions = []
for i in range(8):
    angle = math.radians(10 * i - 35)
    directions.append((math.sin(angle), -math.cos(angle), 0.0))

# Cast every ray in the same physics tick
distances = conn.add_stream(
    lambda: [sc.raycast_distance(origin, d, frame) for d in directions]
)
print(distances())

The function stream casts every ray in the same physics tick, as a LiDAR does.