cubos::engine::Raycast class

System argument which allows performing raycast queries among all entities with colliders.

An example of using this system argument:

cubos.system("do raycast")
.call([](Raycast raycast) {
    if (auto hit = raycast.fire({origin, direction}))
    {
        CUBOS_INFO("Hit {} at {}", hit->entity, hit->point);
    }
});

Public types

struct Hit
Holds the result of a raycast query.
struct Ray
Describes the ray used in a raycast query.

Constructors, destructors, conversion operators

Raycast(Query<Entity, const LocalToWorld&, const BoxCollisionShape&> boxes, Query<Entity, const LocalToWorld&, const CapsuleCollisionShape&, const Position&> capsules)
Constructs.

Public functions

auto fire(Ray ray) -> Opt<Hit>
Fires a ray and returns the first hit.

Function documentation

cubos::engine::Raycast::Raycast(Query<Entity, const LocalToWorld&, const BoxCollisionShape&> boxes, Query<Entity, const LocalToWorld&, const CapsuleCollisionShape&, const Position&> capsules)

Constructs.

Parameters
boxes Query for entities with box colliders.
capsules Query for entities with capsule colliders.

Opt<Hit> cubos::engine::Raycast::fire(Ray ray)

Fires a ray and returns the first hit.

Parameters
ray Ray to fire.
Returns Hit if a hit was found, otherwise nullopt.