nightshade-api 0.38.0

Procedural high level API for the nightshade game engine
Documentation
//! Forces, raycasts, and collision events for entities spawned with a
//! [`Body`](crate::prelude::Body).

use nightshade::prelude::*;

/// Applies an instantaneous impulse to a dynamic entity. Good for jumps,
/// knockback, and explosions.
#[inline]
pub fn push(world: &mut World, entity: Entity, impulse: Vec3) {
    physics_world_apply_impulse(&mut world.resources.physics, entity, impulse);
}

/// Sets a dynamic entity's linear velocity directly. Good for launching
/// projectiles.
#[inline]
pub fn set_velocity(world: &mut World, entity: Entity, velocity: Vec3) {
    physics_world_set_linear_velocity(&mut world.resources.physics, entity, velocity);
}

/// Casts a ray against all physics colliders and returns the closest hit.
#[inline]
pub fn raycast(
    world: &World,
    origin: Vec3,
    direction: Vec3,
    max_distance: f32,
) -> Option<RaycastHit> {
    physics_world_cast_ray(
        &world.resources.physics,
        origin,
        direction,
        max_distance,
        None,
    )
}

/// The collision events from the last physics step.
#[inline]
pub fn collisions(world: &World) -> &[CollisionEvent] {
    physics_world_collision_events(&world.resources.physics)
}