--- a/src/proto2/Physics.cc Tue Dec 02 00:48:21 2008 +0000
+++ b/src/proto2/Physics.cc Tue Dec 02 00:56:31 2008 +0000
@@ -231,15 +231,13 @@
* Direction given as normal of that wall
*/
void PhysicsObject::bounce (Vector normal) {
- if (normal.length() != 0) {
- // Engine::log(DEBUG, "PhysicsObject.bounce") << "Velocity: " << velocity;
+ // normal.sqrLength can't be 0 when got from getNormal()
+ if (normal.sqrLength() != 0) {
Vector nvel = velocity;
- // Engine::log(DEBUG, "PhysicsObject.bounce") << "New Velocity: " << nvel;
-// nvel = nvel - ((1+COLLISION_ELASTICITY)*((nvel*normal)/(normal*normal))*normal);
-
+ // We project the velocity on normal and remove twice that much from velocity
nvel = nvel - ((2)*((nvel*normal)/(normal*normal))*normal);
-// Engine::log(DEBUG, "PhysicsObject.bounce") << "Projection: " << nvel;
velocity = nvel;
+ // We lose some of our speed on collision
this->velocity *= COLLISION_ELASTICITY;
}
}