Skip to main content

gizmo_physics_core/components/
character.rs

1use gizmo_math::Vec3;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5pub struct CharacterController {
6    pub speed: f32,
7    pub jump_speed: f32,
8    pub gravity: f32,
9    pub max_slope_angle: f32, // in radians
10    pub slope_slide_speed: f32,
11    pub step_height: f32,
12
13    #[serde(skip)]
14    pub is_grounded: bool,
15
16    pub target_velocity: Vec3, // Desired movement from input
17
18    pub coyote_time: f32,
19    #[serde(skip)]
20    pub coyote_timer: f32,
21
22    pub jump_buffer_time: f32,
23    #[serde(skip)]
24    pub jump_buffer_timer: f32,
25
26    // ── Su / yüzme ──────────────────────────────────────────
27    /// Batıkken yukarı net kaldırma ivmesi (m/s²). 0 = nötr yüzerlik, >0 yüzeye çıkar; drag ile
28    /// terminal yükseliş hızına oturur.
29    pub buoyancy: f32,
30    /// Sudaki lineer sürüklenme katsayısı (her adım `vel *= 1 - water_drag*dt`). Suyu ağdalı yapar.
31    pub water_drag: f32,
32    /// Yüzme itişinin `target_velocity`'ye ne hızla yaklaştığı (su tepkiselliği).
33    pub swim_acceleration: f32,
34    /// Runtime: karakter şu an bir su hacminde mi (yüzme modu aktif). Serileştirilmez.
35    #[serde(skip)]
36    pub is_submerged: bool,
37}
38
39impl Default for CharacterController {
40    fn default() -> Self {
41        Self {
42            speed: 5.0,
43            jump_speed: 5.0,
44            gravity: 9.81,
45            max_slope_angle: 45.0_f32.to_radians(),
46            slope_slide_speed: 10.0,
47            step_height: 0.3,
48            is_grounded: false,
49            target_velocity: Vec3::ZERO,
50            coyote_time: 0.1,
51            coyote_timer: 0.0,
52            jump_buffer_time: 0.1,
53            jump_buffer_timer: 0.0,
54            buoyancy: 2.0,
55            water_drag: 2.0,
56            swim_acceleration: 8.0,
57            is_submerged: false,
58        }
59    }
60}
61
62gizmo_core::impl_component!(CharacterController);