Skip to content

Commit

Permalink
Twiddle constants
Browse files Browse the repository at this point in the history
  • Loading branch information
janhohenheim committed Aug 21, 2024
1 parent f9332e8 commit f0c8f64
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
20 changes: 14 additions & 6 deletions src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,18 @@ pub struct AvianPickupActor {
/// `max(collider_radius, min_distance)`.\
/// Default: 0.5 m
pub min_distance: Scalar,
/// A number >= 0 that indicates how much easing will be applied to the
/// held prop's velocity when the actor is moving.\
/// A value of 0 means no smoothing, i.e. the prop perfectly follows the actor.\
/// Default: 1.4
pub easing: Scalar,
/// A number >= 0 that indicates how much exponential easing will be applied
/// to the held prop's velocity when the actor is moving.\
/// A value of 0 means no smoothing, i.e. the prop perfectly follows the
/// actor.\
/// Default: 1.3
pub linear_velocity_easing: Scalar,
/// A number >= 0 that indicates how much exponential easing will be applied
/// to the held prop's angular velocity when the actor is rotating.\
/// A value of 0 means no smoothing, i.e. the prop perfectly follows the
/// actor's point of view.\
/// Default: 1.7
pub angular_velocity_easing: Scalar,
}

#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Component, Default, Reflect)]
Expand Down Expand Up @@ -124,7 +131,8 @@ impl Default for AvianPickupActor {
max_mass: 35.0,
pull_force: 100.0,
min_distance: 0.5,
easing: 1.4,
linear_velocity_easing: 1.3,
angular_velocity_easing: 1.7,
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions src/interaction/hold/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ pub(super) fn set_velocities(
// so I reverted to this simpler version. If you need the original version,
// check out the commit aa51b2bc4dbc52049476135ba146b3ba143b681a
let dt = time.delta_seconds();
let inv_dt = dt.recip();
for (shadow, holding, actor) in q_actor.iter_mut() {
// This is used for a bit of easing. We don't need to be careful about
// things like overshooting as we are in a fixed timestep.
// A damping factor of 0 means no easing.
let inv_dt = (dt * f32::exp(actor.easing)).recip();
let prop = holding.0;
// Safety: All props are rigid bodies, so they are guaranteed to have a
// `Position`, `Rotation`, `LinearVelocity`, and `AngularVelocity`.
Expand All @@ -37,10 +34,16 @@ pub(super) fn set_velocities(
let angle = if angle > PI { angle - TAU } else { angle };
let delta_rotation_scaled_axis = axis * angle;

velocity.0 = (delta_position * inv_dt).clamp_length_max(shadow.max_speed);
// This is used for a bit of easing. We don't need to be careful about
// things like overshooting as we are in a fixed timestep.
// Negative because the dt is already inverted
let vel_ease = f32::exp(-actor.linear_velocity_easing);
velocity.0 = (delta_position * inv_dt * vel_ease).clamp_length_max(shadow.max_speed);
velocity.0 = zero_if_near_zero(velocity.0);

angvel.0 = (delta_rotation_scaled_axis * inv_dt).clamp_length_max(shadow.max_angular);
let angvel_ease = f32::exp(-actor.angular_velocity_easing);
angvel.0 = (delta_rotation_scaled_axis * inv_dt * angvel_ease)
.clamp_length_max(shadow.max_angular);
angvel.0 = zero_if_near_zero(angvel.0);
}
}
Expand Down

0 comments on commit f0c8f64

Please sign in to comment.