From c799d94e0a7776eea9f5ca8e32d7aff1a3098e52 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Fri, 16 Feb 2024 00:43:11 +0100 Subject: [PATCH] uwu --- kubi/src/client_physics.rs | 27 +++++++++++++++++---------- kubi/src/player_controller.rs | 22 ++++++++++++++++------ 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/kubi/src/client_physics.rs b/kubi/src/client_physics.rs index f2d9416..0edaa52 100644 --- a/kubi/src/client_physics.rs +++ b/kubi/src/client_physics.rs @@ -23,15 +23,17 @@ impl Default for GlobalClPhysicsConfig { //TODO: actors should be represented by a vertical line, not a point. //XXX: maybe a capsule? (or configurable hull?) +//TODO: per block friction + #[derive(Component)] pub struct ClPhysicsActor { pub disable: bool, pub offset: Vec3, pub forces: Vec3, + pub constant_forces: Vec3, pub velocity: Vec3, pub terminal_velocity: f32, - //TODO: this should be configurable per block - pub ground_friction: f32, + pub decel: Vec3, pub gravity_scale: f32, flag_ground: bool, flag_collision: bool, @@ -42,6 +44,10 @@ impl ClPhysicsActor { self.forces += force; } + pub fn apply_constant_force(&mut self, force: Vec3) { + self.constant_forces += force; + } + pub fn on_ground(&self) -> bool { self.flag_ground } @@ -54,9 +60,11 @@ impl Default for ClPhysicsActor { disable: false, offset: vec3(0., 1.5, 0.), forces: Vec3::ZERO, + constant_forces: Vec3::ZERO, velocity: Vec3::ZERO, terminal_velocity: 40., - ground_friction: 10., + //constant deceleration, in ratio per second. e.g. value of 1 should stop the actor in 1 second. + decel: vec3(0., 0., 0.), gravity_scale: 1., flag_ground: false, flag_collision: false, @@ -145,16 +153,15 @@ pub fn update_client_physics_late( } //Apply velocity - actor_position += actor.velocity * dt.0.as_secs_f32(); + actor_position += (actor.velocity + actor.constant_forces) * dt.0.as_secs_f32(); + actor.constant_forces = Vec3::ZERO; actor_position += actor.offset; transform.0 = Mat4::from_scale_rotation_translation(scale, rotation.normalize(), actor_position); - //Apply friction - // if actor.flag_ground { - // let actor_velocity = actor.velocity; - // let actor_friction = actor.ground_friction; - // actor.velocity -= (actor_velocity * actor_friction * dt.0.as_secs_f32()) * vec3(1., 0., 1.); - // } + //Apply "friction" + // let actor_velocity = actor.velocity; + // let actor_decel = actor.decel; + // actor.velocity -= actor_velocity * actor_decel * dt.0.as_secs_f32(); } // for (_, mut transform) in (&controllers, &mut transforms).iter() { // let (scale, rotation, mut translation) = transform.0.to_scale_rotation_translation(); diff --git a/kubi/src/player_controller.rs b/kubi/src/player_controller.rs index aee4a49..bd0fbc7 100644 --- a/kubi/src/player_controller.rs +++ b/kubi/src/player_controller.rs @@ -86,12 +86,22 @@ fn update_movement( let right = Vec2::from_angle(-euler.0).extend(0.).xzy(); let forward = Vec2::from_angle(-(euler.0 + PI/2.)).extend(0.).xzy(); - actor.apply_force(ctl.speed * ( - (forward * movement.z) + - (right * movement.x) + - //TODO: remove hardcoded jump force - (Vec3::Y * movement.y * 125. * (actor_on_ground as u8 as f32)) - )); + //TODO: remove hardcoded jump force + // actor.apply_constant_force(ctl.speed * ( + // (forward * movement.z) + + // (right * movement.x) + // )); + actor.apply_force( + ctl.speed * ( + (forward * movement.z) + + (right * movement.x) + ) + + Vec3::Y * movement.y * 1250. * (actor_on_ground as u8 as f32) + ); + + // actor.decel = + // (right * (1. - inputs.movement.x.abs()) * 10.) + + // (forward * (1. - inputs.movement.y.abs()) * 10.); // translation += forward * movement.z * ctl.speed * dt.0.as_secs_f32(); // translation += right * movement.x * ctl.speed * dt.0.as_secs_f32();