use crate::prelude::*;
use beet_core::prelude::*;
#[derive(
Debug, Copy, Clone, PartialEq, Deref, DerefMut, Component, Reflect,
)]
#[reflect(Component, Default)]
pub struct ArriveRadius(pub f32);
impl Default for ArriveRadius {
fn default() -> Self { Self(0.7) }
}
pub fn arrive_speed(
position: &Vec3,
target_position: &Vec3,
max_speed: MaxSpeed,
arrive_radius: Option<ArriveRadius>,
) -> MaxSpeed {
if let Some(arrive_radius) = arrive_radius {
let distance = (*target_position - *position).length();
if distance < *arrive_radius {
MaxSpeed(f32::lerp(0.0, max_speed.0, distance / *arrive_radius))
} else {
max_speed
}
} else {
max_speed
}
}