Skip to content

rapier-2d-character-controller.component overview


Table of contents


utils

Rapier2dCharacterControllerComponent (class)

A capsule-shaped kinematic character controller backed by Rapier's own KinematicCharacterController (world.createCharacterController) - the 2D counterpart of Rapier3dCharacterControllerComponent, which this mirrors closely (2D Vector2/scalar rotation instead of 3D Vector3/Quaternion, the snap-to-ground/autostep-vs-jump guard, the hand-rolled pushDynamicBodies, the "reuse the best- up-aligned collision normal, falling back to the previous tick's rather than a flat guess" ground-normal derivation - all identical). See that class's own doc for the full rationale behind each of these; only 2D-specific notes are repeated here. One deliberate divergence: move() here sweeps desiredTranslation as two single-axis passes (horizontal, then any remaining vertical intent) rather than 3D's single combined sweep - see this method's own doc for why.

Signature

export declare class Rapier2dCharacterControllerComponent {
  constructor(
    protected readonly world: Rapier2dWorldComponent,
    protected readonly options: Required<CharacterController2dOptions>,
    protected _bodyDescr: RigidBodyDesc
  )
}

syncColliderTransform (method)

Signature

private syncColliderTransform(): void

ignoredBodiesFilterPredicate (method)

Signature

private ignoredBodiesFilterPredicate(): ((collider: Collider) => boolean) | undefined

move (method)

Signature

move(desiredTranslation: Point2, dt?: number): void

pushDynamicBodies (method)

Mirrors Rapier3dCharacterControllerComponent.pushDynamicBodies exactly, projected into 2D - except hitBodies is passed in by the caller rather than read fresh from this._nativeController.numComputedCollisions()/computedCollision() here, since by the time this runs those may already reflect a later sweep than the horizontal one this method cares about (see move()'s own collectHorizontalHitBodies).

Signature

private pushDynamicBodies(hitBodies: RigidBody[], desiredTranslation: Point2, dt: number | undefined): void

computeGroundNormal (method)

Mirrors Rapier3dCharacterControllerComponent.computeGroundNormal exactly, projected into 2D - see that method's own doc for the full rationale (why a 0-collision grounded call must reuse the previous tick's normal rather than guessing flat up).

Signature

private computeGroundNormal(): Point2 | null

clone (method)

Signature

clone(): Rapier2dCharacterControllerComponent

addToWorld (method)

Signature

addToWorld(world: Rapier2dGgWorld): void

removeFromWorld (method)

Signature

removeFromWorld(world: Rapier2dGgWorld, dispose?: boolean): void

dispose (method)

Signature

dispose(): void

entity (property)

Signature

entity: IEntity<any, any, GgWorldTypeDocRepo<any, any>> | null

name (property)

Signature

name: string

radius (property)

Signature

readonly radius: number

centersDistance (property)

Signature

readonly centersDistance: number

ignoredBodies (property)

See ICharacterController2dComponent.ignoredBodies's doc.

Signature

readonly ignoredBodies: Set<Rapier2dRigidBodyComponent>

_nativeBody (property)

Signature

_nativeBody: RigidBody | null

_nativeCollider (property)

Signature

_nativeCollider: Collider | null

_nativeController (property)

Signature

_nativeController: KinematicCharacterController | null

debugBodySettings (property)

Signature

readonly debugBodySettings: DebugBody2DSettings

collisionGroups (property)

Signature

collisionGroups: number