From f0c8f6453988701b69b4b79cf1bd10fc3d1f34af Mon Sep 17 00:00:00 2001 From: Jan Hohenheim Date: Wed, 21 Aug 2024 03:43:07 +0200 Subject: [PATCH] Twiddle constants --- src/actor.rs | 20 ++++++++++++++------ src/interaction/hold/simulate.rs | 15 +++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index 13ce498..bdb9513 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -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)] @@ -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, } } } diff --git a/src/interaction/hold/simulate.rs b/src/interaction/hold/simulate.rs index 7720c6e..7ba4888 100644 --- a/src/interaction/hold/simulate.rs +++ b/src/interaction/hold/simulate.rs @@ -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`. @@ -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); } }