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;
}
}
/* 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);
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]);
};
};