Bodies
Bodies are an abstraction over the collision response, are manipulated by the physics simulation during the collision resolution phase. This is the component that receives the impulse to bounce off another object.
Physical properties
The physics body modules
Degrees of Freedom
In the realistic simulation, bodies in 2D have 3 degrees of freedom, X axis, Y axis, and rotation, which can be limited using the following
typescript
const actor = new ex.Actor({...});actor.body.limitDegreeOfFreedom.push(ex.DegreeOfFreedom.Rotation);
typescript
const actor = new ex.Actor({...});actor.body.limitDegreeOfFreedom.push(ex.DegreeOfFreedom.Rotation);
Gravity
Bodies can be subject to the global acceleration (commonly used for gravity), the body must also be an CollisionType.Active
typescript
ex.Physics.gravity = ex.vec(0, 800); // accelerate 800 pixels down per second per secondconst actor = new ex.Actor({...});actor.body.collisionType = ex.CollisionType.Active;actor.body.useGravity = true;
typescript
ex.Physics.gravity = ex.vec(0, 800); // accelerate 800 pixels down per second per secondconst actor = new ex.Actor({...});actor.body.collisionType = ex.CollisionType.Active;actor.body.useGravity = true;
Sleep
In the realistic simulation, bodies can fall asleep, which is a common performance enhancement to avoid recalculating collisions for objects that aren't moving much. To adjust the threshold where objects fall asleep use the ex.Physics.sleepEpsilon
.
This can be configured globally setting the ex.Physics.bodiesCanSleepByDefault
, note this should be done before engine construction.
You can also wake or put a body to sleep with the setSleeping(true)
or setSleeping(false)
.