Skip to content

Commit

Permalink
Merge pull request #43 from Aceeri/friction-grounded
Browse files Browse the repository at this point in the history
  • Loading branch information
Aceeri authored Oct 9, 2023
2 parents 19c9c37 + e0c5677 commit 105541a
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/controller/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub fn movement_force(
&Gravity,
&ControllerInput,
&GroundCast,
&Grounded,
&ViableGroundCast,
&ControllerVelocity,
&ControllerMass,
Expand All @@ -98,13 +99,15 @@ pub fn movement_force(
gravity,
input,
ground,
grounded,
viable_ground,
velocity,
mass,
) in &mut query
{
force.linear = Vec3::ZERO;

let grounded = **grounded;
let force_scale = movement.force_scale(&gravity);

let input_dir = input.movement.clamp_length_max(1.0);
Expand Down Expand Up @@ -149,20 +152,23 @@ pub fn movement_force(
};

let relative_velocity = (velocity.linear - last_ground_vel) * force_scale;
let friction_coefficient = if let Some(ground) = viable_ground.current() {
let friction = frictions
.get(controller_entity)
.copied()
.unwrap_or(Friction::default());
let ground_friction = frictions
.get(ground.entity)
.copied()
.unwrap_or(Friction::default());
let friction_coefficient = friction.coefficient.max(ground_friction.coefficient);
friction_coefficient
} else {
// Air damping coefficient
0.25
let friction_coefficient = match viable_ground.current() {
Some(ground) if grounded => {
let friction = frictions
.get(controller_entity)
.copied()
.unwrap_or(Friction::default());
let ground_friction = frictions
.get(ground.entity)
.copied()
.unwrap_or(Friction::default());
let friction_coefficient = friction.coefficient.max(ground_friction.coefficient);
friction_coefficient
}
_ => {
// Air damping coefficient
0.25
}
};

let strength = movement.acceleration.get(mass.mass, dt);
Expand Down

0 comments on commit 105541a

Please sign in to comment.