Skip to content
This repository was archived by the owner on Dec 15, 2019. It is now read-only.

Added minVel and maxVel for body (core) #176

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/core/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// what is its coefficient of friction with another surface with COF = 1?
cof: 0.8,
// what is the view object (mixed) that should be used when rendering?
view: null
view: null,
// The minimum velocity clamp [[Vectorish]] (default: { x: -5, y: -5 }) to restrict velocity of body
minVel: { x: -5, y: -5 },
// The maximum velocity clamp [[Vectorish]] (default: { x: 5, y: 5 }) to restrict velocity of body
maxVel: { x: 5, y: 5 }
};

var uidGen = 1;
Expand Down Expand Up @@ -45,6 +49,10 @@
cof: 0.8,
// what is the view object (mixed) that should be used when rendering?
view: null,
// The minimum velocity clamp [[Vectorish]] (default: { x: -5, y: -5 }) to restrict velocity of body
minVel: { x: -5, y: -5 },
// The maximum velocity clamp [[Vectorish]] (default: { x: 5, y: 5 }) to restrict velocity of body
maxVel: { x: 5, y: 5 },
// the vector offsetting the geometry from its center of mass
offset: Physics.vector(0,0)
}
Expand Down Expand Up @@ -391,13 +399,17 @@
* - acc (Physics.vector): The acceleration vector
*
* Accelerate the body by adding supplied vector to its current acceleration
* After acceleration apply velocity limitation using maxVel and minVel
**/
accelerate: function( acc ){

if ( this.treatment === 'dynamic' ){
this.state.acc.vadd( acc );
}

// Limit velocity with maxVel and minVel
this.state.vel.clamp( this.minVel, this.maxVel );

return this;
},

Expand Down