83 lines
1.6 KiB
Rust
83 lines
1.6 KiB
Rust
use glam::Vec3;
|
|
use kurbo::CubicBez;
|
|
|
|
#[derive(Clone)]
|
|
pub struct JumpComponent
|
|
{
|
|
pub jump_config: JumpConfig,
|
|
}
|
|
|
|
impl JumpComponent
|
|
{
|
|
pub fn new() -> Self
|
|
{
|
|
Self {
|
|
jump_config: JumpConfig::default(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Copy)]
|
|
pub struct JumpConfig
|
|
{
|
|
pub jump_height: f32,
|
|
pub jump_duration: f32,
|
|
pub air_control_force: f32,
|
|
pub max_air_momentum: f32,
|
|
pub air_damping_active: f32,
|
|
pub air_damping_passive: f32,
|
|
pub jump_curve: CubicBez,
|
|
pub jump_context: JumpContext,
|
|
}
|
|
|
|
impl Default for JumpConfig
|
|
{
|
|
fn default() -> Self
|
|
{
|
|
Self {
|
|
jump_height: 2.0,
|
|
jump_duration: 0.15,
|
|
air_control_force: 10.0,
|
|
max_air_momentum: 8.0,
|
|
air_damping_active: 0.4,
|
|
air_damping_passive: 0.9,
|
|
jump_curve: CubicBez::new(
|
|
(0.0, 0.0),
|
|
(0.4, 0.75),
|
|
(0.7, 0.9),
|
|
(1.0, 1.0),
|
|
),
|
|
jump_context: JumpContext::default(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Default, Clone, Copy)]
|
|
pub struct JumpContext
|
|
{
|
|
pub in_progress: bool,
|
|
pub duration: f32,
|
|
pub execution_time: f32,
|
|
pub origin_height: f32,
|
|
pub normal: Vec3,
|
|
}
|
|
|
|
impl JumpContext
|
|
{
|
|
fn start(time: f32, current_height: f32, surface_normal: Vec3) -> Self
|
|
{
|
|
Self {
|
|
in_progress: false,
|
|
duration: 0.0,
|
|
execution_time: time,
|
|
origin_height: current_height,
|
|
normal: surface_normal,
|
|
}
|
|
}
|
|
|
|
pub fn stop(&mut self)
|
|
{
|
|
self.in_progress = false;
|
|
}
|
|
}
|