Skip to main content

BodyComponent

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

Hierarchy

Implements

Index

Constructors

constructor

Properties

publicbounciness

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.

publiccanSleep

canSleep: boolean

Can this body sleep, by default bodies do not sleep

publiccollisionType

collisionType: CollisionType = CollisionType.PreventCollision

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

publicdependencies

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

publicenableFixedUpdateInterpolate

enableFixedUpdateInterpolate: boolean = true

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

publicevents

events: EventEmitter<any> = ...

publicfriction

friction: number = 0.99

The coefficient of friction on this actor

publicgroup

group: CollisionGroup = CollisionGroup.All

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

publicreadonlyid

id: Id<body> = ...

publiclimitDegreeOfFreedom

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

publicoldAcc

oldAcc: Vector = Vector.Zero

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

publicoldTransform

oldTransform: Transform = ...

publicoldVel

oldVel: Vector = ...

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

optionalowner

owner?: Entity<any> = undefined

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

publicsleepMotion

sleepMotion: number

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

publicuseGravity

useGravity: boolean = true

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

publicwakeThreshold

wakeThreshold: number

publicstatic_ID

_ID: number = 0

Accessors

publicacc

  • The current acceleration vector (ax, ay) of the actor in pixels/second/second. An acceleration pointing down such as (0, 100) may be useful to simulate a gravitational effect.


    Returns Vector

  • Parameters

    Returns void

publicactive

  • get active(): boolean
  • Returns if the owner is active


    Returns boolean

publicangularVelocity

  • get angularVelocity(): number
  • set angularVelocity(value: number): void
  • Get the angular velocity in radians/second


    Returns number

  • Set the angular velocity in radians/second


    Parameters

    • value: number

    Returns void

publiccenter

  • @deprecated

    Use globalPos


    Returns Vector

publicglobalPos

  • 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

  • Parameters

    Returns void

publicinertia

  • get inertia(): number
  • Get the moment of inertia from the [[ColliderComponent]]


    Returns number

publicinverseInertia

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


    Returns number

publicinverseMass

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


    Returns number

publicmass

  • get mass(): number
  • set mass(newMass: number): void
  • Returns number

  • Parameters

    • newMass: number

    Returns void

publicmatrix

publicmotion

publicoldGlobalPos

  • The global position of the actor last frame (x, y) in pixels


    Returns Vector

publicoldPos

  • The position of the actor last frame (x, y) in pixels


    Returns Vector

publicoldRotation

  • get oldRotation(): number
  • Gets/sets the rotation of the body from the last frame.


    Returns number

publicoldScale

  • The scale of the actor last frame


    Returns Vector

publicpos

publicrotation

  • get rotation(): number
  • set rotation(val: number): void
  • The rotation of the body in radians


    Returns number

  • Parameters

    • val: number

    Returns void

publicscale

  • The scale vector of the actor


    Returns Vector

  • Parameters

    Returns void

publicscaleFactor

  • get scaleFactor(): Vector
  • set scaleFactor(scaleFactor: Vector): void
  • The scale rate of change of the actor in scale/second


    Returns Vector

  • Parameters

    Returns void

publicsleeping

  • get sleeping(): boolean
  • Whether this body is sleeping or not


    Returns boolean

publictorque

  • get torque(): number
  • set torque(val: number): void
  • The current torque applied to the actor


    Returns number

  • Parameters

    • val: number

    Returns void

publictransform

publicvel

  • The current velocity vector (vx, vy) of the actor in pixels/second


    Returns Vector

  • Parameters

    Returns void

Methods

publicapplyAngularImpulse

  • Apply only angular impulse to the body


    Parameters

    Returns void

publicapplyImpulse

  • Apply a specific impulse to the body


    Parameters

    Returns void

publicapplyLinearImpulse

  • applyLinearImpulse(impulse: Vector): void
  • Apply only linear impulse to the body


    Parameters

    Returns void

publiccaptureOldTransform

  • captureOldTransform(): void
  • Sets the old versions of pos, vel, acc, and scale.


    Returns void

publicclone

  • Clones any properties on this component, if that property value has a clone() method it will be called


    Returns BodyComponent

optionalonAdd

  • onAdd(owner: Entity<any>): void
  • Optional callback called when a component is added to an entity


    Parameters

    Returns void

optionalonRemove

  • onRemove(previousOwner: Entity<any>): void
  • Optional callback called when a component is removed from an entity


    Parameters

    Returns void

publicsetSleeping

  • setSleeping(sleeping: boolean): void
  • Set the sleep state of the body


    Parameters

    • sleeping: boolean

    Returns void

publicupdateMotion

  • updateMotion(): void
  • Update body's [[BodyComponent.sleepMotion]] for the purpose of sleeping


    Returns void

publicupdatePhysicsConfig

  • updatePhysicsConfig(config: Required<{ canSleepByDefault?: boolean; defaultMass?: number; sleepBias?: number; sleepEpsilon?: number; wakeThreshold?: number }>): void
  • Called by excalibur to update physics config defaults if they change


    Parameters

    • config: Required<{ canSleepByDefault?: boolean; defaultMass?: number; sleepBias?: number; sleepEpsilon?: number; wakeThreshold?: number }>

    Returns void

publicstaticupdateDefaultPhysicsConfig

  • updateDefaultPhysicsConfig(config: Required<{ canSleepByDefault?: boolean; defaultMass?: number; sleepBias?: number; sleepEpsilon?: number; wakeThreshold?: number }>): void
  • Called by excalibur to update defaults


    Parameters

    • config: Required<{ canSleepByDefault?: boolean; defaultMass?: number; sleepBias?: number; sleepEpsilon?: number; wakeThreshold?: number }>

    Returns void