]> isoptera.lcsc.edu Git - engine26/.git/commitdiff
Fixed bouncing - I had my head on backwards when we set up the direction change
authorSeth Long <sslong@lcsc.edu>
Tue, 27 Oct 2026 18:56:41 +0000 (11:56 -0700)
committerSeth Long <sslong@lcsc.edu>
Tue, 27 Oct 2026 18:56:41 +0000 (11:56 -0700)
projectile.h

index 3746db258f54fab86029c8ceff0c8f1144f03d4a..2d30620fcbf512bedb9d46f821b345b5118270da 100644 (file)
@@ -4,7 +4,7 @@
 
 class Projectile : public GameObject {
 public:
-       constexpr static float proj_size = .6;
+       constexpr static float proj_size = .3;
        vector<vec3> velocities;
        vector<float> 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]);
        };
 };