Skip to content

Commit d1c7a34

Browse files
committed
Fixed stupid bug preventing damping to be changed during simulation.. Thanks to @Fishrock123!
1 parent 3802602 commit d1c7a34

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

src/objects/Body.js

+2-14
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,6 @@ function Body(options){
373373

374374
this.concavePath = null;
375375

376-
this.lastDampingScale = 1;
377-
this.lastAngularDampingScale = 1;
378-
this.lastDampingTimeStep = -1;
379-
380376
this._wakeUpAfterNarrowphase = false;
381377

382378
this.updateMassProperties();
@@ -799,17 +795,9 @@ Body.prototype.addConstraintVelocity = function(){
799795
*/
800796
Body.prototype.applyDamping = function(dt){
801797
if(this.type === Body.DYNAMIC){ // Only for dynamic bodies
802-
803-
// Since Math.pow generates garbage we check if we can reuse the scaling coefficient from last step
804-
if(dt !== this.lastDampingTimeStep){
805-
this.lastDampingScale = Math.pow(1.0 - this.damping,dt);
806-
this.lastAngularDampingScale = Math.pow(1.0 - this.angularDamping,dt);
807-
this.lastDampingTimeStep = dt;
808-
}
809-
810798
var v = this.velocity;
811-
vec2.scale(v,v,this.lastDampingScale);
812-
this.angularVelocity *= this.lastAngularDampingScale;
799+
vec2.scale(v, v, Math.pow(1.0 - this.damping,dt));
800+
this.angularVelocity *= Math.pow(1.0 - this.angularDamping,dt);
813801
}
814802
};
815803

0 commit comments

Comments
 (0)