]> git.tdb.fi Git - libs/game.git/commitdiff
Don't apply more friction than it takes to nullify the velocity
authorMikko Rasa <tdb@tdb.fi>
Fri, 25 Nov 2022 19:38:09 +0000 (21:38 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 25 Nov 2022 19:38:09 +0000 (21:38 +0200)
examples/bassteroids/source/physics.cpp

index 2453fd90ec82be2ed213eaec91da41c642b1b21f..21c8bd4e9ed7f4b3f57d7aad95ee3bcbd4ff58a8 100644 (file)
@@ -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<float, 2> impulse = c.normal*reaction+tangent*friction;
                entity1.velocity += impulse*entity1.inverse_mass;
                entity2.velocity -= impulse*entity2.inverse_momi;