RigidBody

The RigidBody component enables physics movement for an entity, making it move under velocity, acceleration, and gravity. It works together with a collider on the same entity. See Physics for an overview.

Body types

TypeDescription
RigidBodyType.DynamicAffected by gravity and velocity, and moved by collisions with other bodies. For objects that need full physical behavior.
RigidBodyType.KinematicMoved by applied velocity, but unaffected by gravity or collisions from other bodies. For moving platforms or scripted movement.
RigidBodyType.StaticImmobile. Unaffected by velocity or gravity. For walls and level geometry.

Options

OptionTypeDefaultDescription
typeRigidBodyTypeDynamicThe body type.
velocityVector2(0, 0)Velocity in pixels per second. For Dynamic and Kinematic bodies.
accelerationVector2(0, 0)Acceleration in pixels per second squared. For Dynamic and Kinematic bodies.
gravitynumber0Gravity in pixels per second squared. For Dynamic bodies only.

Example

import { Transform, BoxCollider, RigidBody, RigidBodyType } from "angry-pixel";

this.entityManager.createEntity([
    new Transform(),
    new BoxCollider({ width: 16, height: 16, layer: "Player" }),
    new RigidBody({ type: RigidBodyType.Dynamic, gravity: 1000 }),
]);