Add the Ability to Control the Side-to-Side Grip of a Raycast Vehicle Wheels
This commit is contained in:
@@ -44,7 +44,7 @@ pub fn init_world(testbed: &mut Testbed) {
|
|||||||
];
|
];
|
||||||
|
|
||||||
for pos in wheel_positions {
|
for pos in wheel_positions {
|
||||||
vehicle.add_wheel(pos, -Vector::y(), Vector::z(), hh, hh / 4.0, &tuning);
|
vehicle.add_wheel(pos, -Vector::y(), Vector::z(), hh, hh / 4.0, 1.0, &tuning);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ pub struct WheelTuning {
|
|||||||
pub suspension_damping: Real,
|
pub suspension_damping: Real,
|
||||||
/// The maximum distance the suspension can travel before and after its resting length.
|
/// The maximum distance the suspension can travel before and after its resting length.
|
||||||
pub max_suspension_travel: Real,
|
pub max_suspension_travel: Real,
|
||||||
/// Parameter controlling how much traction the tire his.
|
/// Parameter controlling how much traction the tire has.
|
||||||
///
|
///
|
||||||
/// The larger the value, the more instantaneous braking will happen (with the risk of
|
/// The larger the value, the more instantaneous braking will happen (with the risk of
|
||||||
/// causing the vehicle to flip if it’s too strong).
|
/// causing the vehicle to flip if it’s too strong).
|
||||||
@@ -86,13 +86,16 @@ struct WheelDesc {
|
|||||||
///
|
///
|
||||||
/// Increase this value if the suspension appears to overshoot.
|
/// Increase this value if the suspension appears to overshoot.
|
||||||
pub damping_relaxation: Real,
|
pub damping_relaxation: Real,
|
||||||
/// Parameter controlling how much traction the tire his.
|
/// Parameter controlling how much traction the tire has.
|
||||||
///
|
///
|
||||||
/// The larger the value, the more instantaneous braking will happen (with the risk of
|
/// The larger the value, the more instantaneous braking will happen (with the risk of
|
||||||
/// causing the vehicle to flip if it’s too strong).
|
/// causing the vehicle to flip if it’s too strong).
|
||||||
pub friction_slip: Real,
|
pub friction_slip: Real,
|
||||||
/// The maximum force applied by the suspension.
|
/// The maximum force applied by the suspension.
|
||||||
pub max_suspension_force: Real,
|
pub max_suspension_force: Real,
|
||||||
|
/// The multiplier of friction between
|
||||||
|
/// a tire and the collider it's on top of.
|
||||||
|
pub initial_side_friction_stiffness: Real,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
@@ -128,7 +131,7 @@ pub struct Wheel {
|
|||||||
///
|
///
|
||||||
/// Increase this value if the suspension appears to overshoot.
|
/// Increase this value if the suspension appears to overshoot.
|
||||||
pub damping_relaxation: Real,
|
pub damping_relaxation: Real,
|
||||||
/// Parameter controlling how much traction the tire his.
|
/// Parameter controlling how much traction the tire has.
|
||||||
///
|
///
|
||||||
/// The larger the value, the more instantaneous braking will happen (with the risk of
|
/// The larger the value, the more instantaneous braking will happen (with the risk of
|
||||||
/// causing the vehicle to flip if it’s too strong).
|
/// causing the vehicle to flip if it’s too strong).
|
||||||
@@ -157,6 +160,9 @@ pub struct Wheel {
|
|||||||
/// The force applied by the suspension.
|
/// The force applied by the suspension.
|
||||||
pub wheel_suspension_force: Real,
|
pub wheel_suspension_force: Real,
|
||||||
skid_info: Real,
|
skid_info: Real,
|
||||||
|
/// The multiplier of friction between
|
||||||
|
/// a tire and the collider it's on top of.
|
||||||
|
pub side_friction_stiffness: Real,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Wheel {
|
impl Wheel {
|
||||||
@@ -189,6 +195,7 @@ impl Wheel {
|
|||||||
skid_info: 0.0,
|
skid_info: 0.0,
|
||||||
side_impulse: 0.0,
|
side_impulse: 0.0,
|
||||||
forward_impulse: 0.0,
|
forward_impulse: 0.0,
|
||||||
|
side_friction_stiffness: info.initial_side_friction_stiffness,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,6 +253,7 @@ impl DynamicRayCastVehicleController {
|
|||||||
axle_cs: Vector<Real>,
|
axle_cs: Vector<Real>,
|
||||||
suspension_rest_length: Real,
|
suspension_rest_length: Real,
|
||||||
radius: Real,
|
radius: Real,
|
||||||
|
side_friction_stiffness: Real,
|
||||||
tuning: &WheelTuning,
|
tuning: &WheelTuning,
|
||||||
) -> &mut Wheel {
|
) -> &mut Wheel {
|
||||||
let ci = WheelDesc {
|
let ci = WheelDesc {
|
||||||
@@ -260,6 +268,7 @@ impl DynamicRayCastVehicleController {
|
|||||||
friction_slip: tuning.friction_slip,
|
friction_slip: tuning.friction_slip,
|
||||||
max_suspension_travel: tuning.max_suspension_travel,
|
max_suspension_travel: tuning.max_suspension_travel,
|
||||||
max_suspension_force: tuning.max_suspension_force,
|
max_suspension_force: tuning.max_suspension_force,
|
||||||
|
initial_side_friction_stiffness: side_friction_stiffness,
|
||||||
};
|
};
|
||||||
|
|
||||||
let wheel_id = self.wheels.len();
|
let wheel_id = self.wheels.len();
|
||||||
@@ -509,8 +518,6 @@ impl DynamicRayCastVehicleController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const SIDE_FRICTION_STIFFNESS2: Real = 1.0;
|
|
||||||
|
|
||||||
fn update_friction(&mut self, bodies: &mut RigidBodySet, colliders: &ColliderSet, dt: Real) {
|
fn update_friction(&mut self, bodies: &mut RigidBodySet, colliders: &ColliderSet, dt: Real) {
|
||||||
let num_wheels = self.wheels.len();
|
let num_wheels = self.wheels.len();
|
||||||
|
|
||||||
@@ -574,7 +581,7 @@ impl DynamicRayCastVehicleController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
wheel.side_impulse *= Self::SIDE_FRICTION_STIFFNESS2;
|
wheel.side_impulse *= wheel.side_friction_stiffness;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user