From ee795ccd604ddf1efa12c1f832557ae95dadfe00 Mon Sep 17 00:00:00 2001 From: Seth Long Date: Tue, 27 Oct 2026 11:56:41 -0700 Subject: [PATCH] Fixed bouncing - I had my head on backwards when we set up the direction change --- projectile.h | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/projectile.h b/projectile.h index 3746db2..2d30620 100644 --- a/projectile.h +++ b/projectile.h @@ -4,7 +4,7 @@ class Projectile : public GameObject { public: - constexpr static float proj_size = .6; + constexpr static float proj_size = .3; vector velocities; vector times_to_live; @@ -35,7 +35,7 @@ public: } } /* Required for collision detection */ - float fast_check_distance(size_t instance) {return 0.2;} + float fast_check_distance(size_t instance) {return proj_size;} vec3 closest_point(vec3 other, size_t instance) { vec3 cmpos = get_center(instance); @@ -56,14 +56,25 @@ public: void report_collision(GameObject *other, size_t other_instance, size_t our_instance) { vec3 our_center = get_center(our_instance); vec3 other_cp = other->closest_point(our_center, other_instance); - if(other_cp == our_center) - printf("our_center is the closest point!\n"); /* Now figure out what shape the other object is! */ - if(other_cp.x == our_center.x) + /* If we could get a normal vector for the surface we hit... */ + bool rx = true, ry = true, rz = true; + if(fabs(other_cp.x - our_center.x) < 0.01) + rx = false; + if(fabs(other_cp.y - our_center.y) < 0.01) + ry = false; + if(fabs(other_cp.z - our_center.z) < 0.01) + rz = false; + + if(rx) velocities[our_instance] *= vec3(-1, 1, 1); - if(other_cp.y == our_center.y) + if(ry) velocities[our_instance] *= vec3(1, -1, 1); - if(other_cp.z == our_center.z) + if(rz) velocities[our_instance] *= vec3(1, 1, -1); + + /* Might not need this - applies one timestep of movement to make sure this projectile + * isn't in contact with the wall anymore so it won't bounce right back */ + models[our_instance] = translate(models[our_instance], velocities[our_instance]); }; }; -- 2.47.3