From 146d401aff5a45acc2cccfd59c2d009c3579dbc0 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Wed, 19 Jun 2024 17:15:09 -0700 Subject: [PATCH] kinda working friction sim --- src/action/systems.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/action/systems.rs b/src/action/systems.rs index 72f21f7..e0e8bd6 100644 --- a/src/action/systems.rs +++ b/src/action/systems.rs @@ -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);