Add static and dynamic friction

This commit is contained in:
sergeypdev 2025-03-16 00:22:20 +04:00
parent fb1643e6e6
commit 2410ed9b4b

View File

@ -431,14 +431,21 @@ pgs_solve_contacts :: proc(
}
{
FRICTION :: 0.6
friction_clamp := contact.total_normal_impulse[point_idx] * FRICTION
DYNAMIC_FRICTION :: 0.6
STATIC_FRICTION :: 0.8
STATIC_FRICTION_VELOCITY_THRESHOLD :: 0.01
delta_v_tang := Vec2 {
lg.dot(delta_v, manifold.tangent),
lg.dot(delta_v, manifold.bitangent),
}
use_static_friction :=
lg.dot(delta_v_tang, delta_v_tang) <
STATIC_FRICTION_VELOCITY_THRESHOLD * STATIC_FRICTION_VELOCITY_THRESHOLD
friction: f32 = use_static_friction ? STATIC_FRICTION : DYNAMIC_FRICTION
friction_clamp := contact.total_normal_impulse[point_idx] * friction
incremental_impulse := -inv_w * delta_v_tang
new_total_impulse: Vec2 = lg.clamp(