kinda working friction sim
This commit is contained in:
parent
c3e955c1cd
commit
146d401aff
1 changed files with 25 additions and 1 deletions
|
@ -176,16 +176,40 @@ pub(super) fn wheel_forces(
|
||||||
// do steering's share
|
// do steering's share
|
||||||
if steering.is_some() {
|
if steering.is_some() {
|
||||||
let thrust = norm.cross(xform.back().into());
|
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
|
// do the friction's share
|
||||||
|
//
|
||||||
|
// first the brakes
|
||||||
if input.brake {
|
if input.brake {
|
||||||
friction.coefficient = 2.0;
|
friction.coefficient = 2.0;
|
||||||
} else {
|
} else {
|
||||||
friction.coefficient = 0.0;
|
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
|
// show the force
|
||||||
#[cfg(feature = "inspector")]
|
#[cfg(feature = "inspector")]
|
||||||
gizmos.arrow(pos, pos + force, Color::RED);
|
gizmos.arrow(pos, pos + force, Color::RED);
|
||||||
|
|
Loading…
Reference in a new issue