From: Mikko Rasa Date: Fri, 25 Nov 2022 19:38:09 +0000 (+0200) Subject: Don't apply more friction than it takes to nullify the velocity X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=15afb5af144074d127cfaab7e2df769a561c1448;p=libs%2Fgame.git Don't apply more friction than it takes to nullify the velocity --- diff --git a/examples/bassteroids/source/physics.cpp b/examples/bassteroids/source/physics.cpp index 2453fd9..21c8bd4 100644 --- a/examples/bassteroids/source/physics.cpp +++ b/examples/bassteroids/source/physics.cpp @@ -191,7 +191,7 @@ void Physics::apply_impulses() float friction_coeff = 0.1f; float inv_mass_sum = entity1.inverse_mass+entity2.inverse_mass; float reaction = (1+restitution)*inner_product(v_rel, c.normal)/inv_mass_sum; - float friction = reaction*friction_coeff; + float friction = min(reaction*friction_coeff, v_tan/inv_mass_sum); LinAl::Vector impulse = c.normal*reaction+tangent*friction; entity1.velocity += impulse*entity1.inverse_mass; entity2.velocity -= impulse*entity2.inverse_momi;