Skip to content

Commit

Permalink
Fixed stupid bug preventing damping to be changed during simulation..…
Browse files Browse the repository at this point in the history
… Thanks to @Fishrock123!
  • Loading branch information
schteppe committed Jul 27, 2014
1 parent 3802602 commit d1c7a34
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/objects/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,6 @@ function Body(options){

this.concavePath = null;

this.lastDampingScale = 1;
this.lastAngularDampingScale = 1;
this.lastDampingTimeStep = -1;

this._wakeUpAfterNarrowphase = false;

this.updateMassProperties();
Expand Down Expand Up @@ -799,17 +795,9 @@ Body.prototype.addConstraintVelocity = function(){
*/
Body.prototype.applyDamping = function(dt){
if(this.type === Body.DYNAMIC){ // Only for dynamic bodies

// Since Math.pow generates garbage we check if we can reuse the scaling coefficient from last step
if(dt !== this.lastDampingTimeStep){
this.lastDampingScale = Math.pow(1.0 - this.damping,dt);
this.lastAngularDampingScale = Math.pow(1.0 - this.angularDamping,dt);
this.lastDampingTimeStep = dt;
}

var v = this.velocity;
vec2.scale(v,v,this.lastDampingScale);
this.angularVelocity *= this.lastAngularDampingScale;
vec2.scale(v, v, Math.pow(1.0 - this.damping,dt));
this.angularVelocity *= Math.pow(1.0 - this.angularDamping,dt);
}
};

Expand Down

2 comments on commit d1c7a34

@Fishrock123
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!!!! I will try the patch later today!

@Fishrock123
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, seems to be working! Thanks @schteppe!

@photonstorm this should probably be cherry-picked into 2.0.8 if there are other fixes that necessitate that version. :)

Please sign in to comment.