From 07f534f796489765e415c6d43534b01093acb652 Mon Sep 17 00:00:00 2001 From: Sara Date: Tue, 24 Oct 2023 23:57:38 +0200 Subject: [PATCH] fixed collision solving causing an inability to escape a surface --- src/physics_entity.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/physics_entity.c b/src/physics_entity.c index a19dd36..8c7c672 100644 --- a/src/physics_entity.c +++ b/src/physics_entity.c @@ -80,7 +80,9 @@ void physics_entity_solve_contacts(PhysicsEntity self, List* contacts) { } Vector dir = vnormalizedf(vsubf(rigidbody_get_transform(body)->position, pre_solve.position)); Vector vel = rigidbody_get_velocity(body); - vel = vsubf(vel, vprojectf(dir, vel)); + float dot = vdotf(dir, vel); + if(dot < 0) + vel = vsubf(vel, vmulff(dir, dot)); rigidbody_set_velocity(body, vel); }