nightshade 0.57.0

A cross-platform data-oriented game engine.
Documentation
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct SceneCharacterController {
    pub shape: SceneCharacterShape,
    pub max_speed: f32,
    pub acceleration: f32,
    pub jump_impulse: f32,
    pub crouch_enabled: bool,
    pub crouch_speed_multiplier: f32,
    pub sprint_speed_multiplier: f32,
    pub standing_half_height: f32,
    pub crouching_half_height: f32,
    pub scale: f32,
    pub config: SceneCharacterControllerConfig,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum SceneCharacterShape {
    Capsule { half_height: f32, radius: f32 },
    Ball { radius: f32 },
    Cuboid { hx: f32, hy: f32, hz: f32 },
}

impl Default for SceneCharacterShape {
    fn default() -> Self {
        Self::Capsule {
            half_height: 0.9,
            radius: 0.3,
        }
    }
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(default)]
pub struct SceneCharacterControllerConfig {
    pub offset: f32,
    pub max_slope_climb_angle: f32,
    pub min_slope_slide_angle: f32,
    pub autostep_max_height: Option<f32>,
    pub autostep_min_width: Option<f32>,
    pub autostep_include_dynamic_bodies: bool,
    pub snap_to_ground: Option<f32>,
}

impl Default for SceneCharacterController {
    fn default() -> Self {
        Self {
            shape: SceneCharacterShape::default(),
            max_speed: 5.0,
            acceleration: 50.0,
            jump_impulse: 8.0,
            crouch_enabled: true,
            crouch_speed_multiplier: 0.5,
            sprint_speed_multiplier: 1.6,
            standing_half_height: 0.9,
            crouching_half_height: 0.45,
            scale: 1.0,
            config: SceneCharacterControllerConfig::default(),
        }
    }
}

/// The record's defaults, stated here rather than borrowed from the physics
/// plugin so the format keeps them when that plugin is not compiled. The
/// plugin's live defaults are its own; these are what an unspecified field in a
/// scene means.
impl Default for SceneCharacterControllerConfig {
    fn default() -> Self {
        Self {
            offset: 0.01,
            max_slope_climb_angle: 45_f32.to_radians(),
            min_slope_slide_angle: 30_f32.to_radians(),
            autostep_max_height: Some(0.3),
            autostep_min_width: Some(0.2),
            autostep_include_dynamic_bodies: false,
            snap_to_ground: Some(0.2),
        }
    }
}