kinda working friction sim

This commit is contained in:
Joe Ardent 2024-06-19 17:15:09 -07:00
parent c3e955c1cd
commit 146d401aff

View file

@ -176,16 +176,40 @@ pub(super) fn wheel_forces(
// do steering's share
if steering.is_some() {
let thrust = norm.cross(xform.back().into());
force += yaw * thrust;
force += 5.0 * yaw * thrust;
}
let forward = if steering.is_some() {
let angle = yaw_to_angle(yaw);
let rot = Quat::from_axis_angle(Vec3::Y, angle);
Transform::from_rotation(rot).forward()
} else {
xform.forward()
};
// do the friction's share
//
// first the brakes
if input.brake {
friction.coefficient = 2.0;
} else {
friction.coefficient = 0.0;
}
// now static simulated friction
let alignment = forward.dot(velocity.linvel);
let alignment = if alignment.is_normal() || alignment == 0.0 {
alignment
} else {
1.0
};
dbg!(alignment);
let sign = alignment.signum();
let slide = sign * (1.0 - alignment.abs());
let perp = forward.cross(norm).normalize();
force += slide * perp;
// show the force
#[cfg(feature = "inspector")]
gizmos.arrow(pos, pos + force, Color::RED);