Damped oscillation.
authorekku
Tue, 18 Nov 2008 21:32:26 +0000
changeset 63 1969a1447ef9
parent 62 c72f8fca1d11
child 64 81302d3350eb
Damped oscillation.
src/proto2/Physics.cc
--- a/src/proto2/Physics.cc	Tue Nov 18 21:20:35 2008 +0000
+++ b/src/proto2/Physics.cc	Tue Nov 18 21:32:26 2008 +0000
@@ -43,10 +43,18 @@
 
     if (newPosition.x < 0 || (newPosition.x > world.dimensions.x)) {
         // CRASH!
-        this->velocity.x *= -1;
+        this->velocity.x *= -0.5;
+		
+		// If the velocity drops under some fixed constant we decide it is zero.
+		// This is to prevent the object from bouncing eternally.
+		if(this->velocity.x < 0.1)
+			this->velocity.x = 0;
     }
 	else if(newPosition.y < 0 || (newPosition.y >= world.dimensions.y)) {
-	   this->velocity.y *= -1; 
+		this->velocity.y *= -0.3;
+
+		if(this->velocity.y < 0.1)
+			this->velocity.y = 0;
 	}
 	else {
         this->position = newPosition;