This version has a nasty bug in collision detection. We'll get rid of it by making the collision detection to return te point
authorsaiam
Sun, 30 Nov 2008 23:45:01 +0000
changeset 154 78d144a48354
parent 153 73402d5b778e
child 155 1550a5eb725a
This version has a nasty bug in collision detection. We'll get rid of it by making the collision detection to return te point
of collision.
src/proto2/Physics.cc
--- a/src/proto2/Physics.cc	Sun Nov 30 23:00:26 2008 +0000
+++ b/src/proto2/Physics.cc	Sun Nov 30 23:45:01 2008 +0000
@@ -148,7 +148,8 @@
     if (!this->inAir) {
         if (total.x != 0)
             this->position = walk(total.x > 0);
-        return; // argh
+        return; 
+        //total.x = 0;
     }
 
     integrate(total, PHYSICS_TICK_MS);
@@ -166,18 +167,20 @@
 
     while ((position-reached).length() < diffVec.length()) {
         // Check if any of the shapes points collide
-        for (uint64_t i = 0; i < shape.size(); i ++) {
+        for (uint64_t i = 0; i < shape.size(); i++) {
             if (world.getType(reached+shape[i]) != EMPTY) {  // Collision
-                this->bounce(world.getNormal(reached+shape[i], 
-                                             reached-unitVector+shape[i]));
+                if (inAir) {
+                    //                    Engine::log(DEBUG, "Here");
+                    this->bounce(world.getNormal(reached+shape[i], 
+                                                 reached-unitVector+shape[i]));
+                    //this->velocity *= COLLISION_ELASTICITY;
+                }
                 reached = reached - unitVector; // Return to last point
                 collided = true;
-                this->velocity *= COLLISION_ELASTICITY;
                 if (this->velocity.length() < PLAYER_MIN_SPEED) {
                     this->inAir = false;
                     this->velocity = Vector(0,0);
                 }
-                
                 break;
             }
         }
@@ -243,7 +246,7 @@
         //TODO: it shouldn't just stop on collision
     }
     this->position = newPosition;
-    //    Engine::log(DEBUG, "PhysicsObject.updatePosition") << "Pos: " << this->position;
+    Engine::log(DEBUG, "PhysicsObject.updatePosition") << "Pos: " << this->position;
 }
 
 /**
@@ -285,13 +288,14 @@
  */
 void PhysicsObject::bounce (Vector normal) {
     if (normal.length() != 0) {
-        //        Engine::log(DEBUG, "PhysicsObject.bounce") << "Velocity: " << velocity;
+        // Engine::log(DEBUG, "PhysicsObject.bounce") << "Velocity: " << velocity;
         Vector nvel = velocity;
         //        Engine::log(DEBUG, "PhysicsObject.bounce") << "New Velocity: " << nvel;
         nvel = nvel - (2*((nvel*normal)/(normal*normal))*normal);
         //        Engine::log(DEBUG, "PhysicsObject.bounce") << "Projection: " << nvel;
         velocity = nvel;
-       }
+        this->velocity *= COLLISION_ELASTICITY;
+    }
 }
 
 /**