Body describes all the physical properties pos, vel, acc, rotation, angular velocity for the purpose of of physics simulation.

Hierarchy

Implements

Constructors

Properties

__oldTransformCaptured: boolean = false

Indicates whether the old transform has been captured at least once for interpolation

bounciness: number = 0.2

The also known as coefficient of restitution of this actor, represents the amount of energy preserved after collision or the bounciness. If 1, it is 100% bouncy, 0 it completely absorbs.

canSleep: boolean = Physics.bodiesCanSleepByDefault

Can this body sleep, by default bodies do not sleep

collisionType: CollisionType = CollisionType.PreventCollision

Collision type for the rigidbody physics simulation, by default [[CollisionType.PreventCollision]]

dependencies: (typeof TransformComponent | typeof MotionComponent)[] = ...

Optionally list any component types this component depends on If the owner entity does not have these components, new components will be added to the entity

Only components with zero-arg constructors are supported as automatic component dependencies

enableFixedUpdateInterpolate: boolean = true

Enable or disabled the fixed update interpolation, by default interpolation is on.

events: EventEmitter<any> = ...
friction: number = 0.99

The coefficient of friction on this actor

group: CollisionGroup = CollisionGroup.All

The collision group for the body's colliders, by default body colliders collide with everything

id: Id<"body"> = ...
limitDegreeOfFreedom: DegreeOfFreedom[] = []

Degrees of freedom to limit

Note: this only limits responses in the realistic solver, if velocity/angularVelocity is set the actor will still respond

oldAcc: Vector = Vector.Zero

Gets/sets the acceleration of the actor from the last frame. This does not include the global acc [[Physics.acc]].

oldVel: Vector = ...

The velocity of the actor last frame (vx, vy) in pixels/second

optional?: ComponentCtor<Component<string>>[]
owner?: Entity = null

Current owning [[Entity]], if any, of this component. Null if not added to any [[Entity]]

sleepMotion: number = ...

Amount of "motion" the body has before sleeping. If below [[Physics.sleepEpsilon]] it goes to "sleep"

type: "ex.body" = 'ex.body'

Type of this component, must be a unique type among component types in you game.

useGravity: boolean = true

Should use global gravity [[Physics.gravity]] in it's physics simulation, default is true

_ID: number = 0

Accessors

  • get globalPos(): Vector
  • The (x, y) position of the actor this will be in the middle of the actor if the [[Actor.anchor]] is set to (0.5, 0.5) which is default. If you want the (x, y) position to be the top left of the actor specify an anchor of (0, 0).

    Returns Vector

  • set globalPos(val): void
  • Parameters

    Returns void

  • get inverseInertia(): number
  • Get the inverse moment of inertial from the [[ColliderComponent]]. If [[CollisionType.Fixed]] this is 0, meaning "infinite" mass

    Returns number

  • get inverseMass(): number
  • The inverse mass (1/mass) of the body. If [[CollisionType.Fixed]] this is 0, meaning "infinite" mass

    Returns number

Methods