ray_cast.cast method

cast(self, origin: Vector3, direction: Vector3) -> Result:

Casts a ray from origin towards direction. The ray length is infinite.

If the ray hits an item it returns a Result, otherwise null.

Example

# Casts a ray from the camera position towards the camera direction every frame
def ray_cast_action(dt):
    hit_result = ray_cast.cast(camera.transform.position, camera.transform.forward)
    if hit_result is not None:
        print('Ray hit item: {}'.format(hit_result.item.name))
    else:
        print('Ray hit no item.')

time.schedule_repeating(ray_cast_action)

Parameters

  • origin: Vector3

    starting point of the ray.

  • direction: Vector3

    direction of the ray.

Returns

hit result. Returns null when no item is hit.