d954mas/defold-box2d/box2d
Box2D physics: worlds, bodies, fixtures, shapes and joints.
- GitHub: d954mas/defold-box2d — pinned to
1.0.3- Pick a release from d954mas/defold-box2d releases and add its Source code (zip) URL (or a packaged
.zipasset, if the library ships one) togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as box2d from "box2d"
- Pick a release from d954mas/defold-box2d releases and add its Source code (zip) URL (or a packaged
Functions
NewWorld(gravity?:Vector3):WorldNewDebugDraw(data:DebugDrawCallbacks):DebugDrawNewPolygonShape():PolygonShapeNewCircleShape():CircleShapeNewChainShape():ChainShapeNewEdgeShape():EdgeShapeb2LinearStiffness(frequencyHertz: number, dampingRatio: number, bodyA:Body, bodyB:Body): LuaMultiReturn<[ stiffness: number, damping: number ]>b2AngularStiffness(frequencyHertz: number, dampingRatio: number, bodyA:Body, bodyB:Body): LuaMultiReturn<[ stiffness: number, damping: number ]>InitializeRevoluteJointDef(bodyA:Body, bodyB:Body, anchor:Vector3):RevoluteJointDefInitializePrismaticJointDef(bodyA:Body, bodyB:Body, anchor:Vector3, axis:Vector3):PrismaticJointDefInitializeDistanceJointDef(bodyA:Body, bodyB:Body, anchorA:Vector3, anchorB:Vector3):DistanceJointDefInitializePulleyJointDef(bodyA:Body, bodyB:Body, groundAnchorA:Vector3, groundAnchorB:Vector3, anchorA:Vector3, anchorB:Vector3, ratio: number):PulleyJointDefInitializeMouseJointDef(bodyA:Body, bodyB:Body):MouseJointDefInitializeGearJointDef(bodyA:Body, bodyB:Body, joint1:RevoluteJoint|PrismaticJoint, joint2:RevoluteJoint|PrismaticJoint):GearJointDefInitializeWheelJointDef(bodyA:Body, bodyB:Body, anchor:Vector3, axis:Vector3):WheelJointDefInitializeWeldJointDef(bodyA:Body, bodyB:Body, anchor:Vector3):WeldJointDefInitializeFrictionJointDef(bodyA:Body, bodyB:Body, anchor:Vector3):FrictionJointDefInitializeMotorJointDef(bodyA:Body, bodyB:Body):MotorJointDef
NewWorld(gravity?: Vector3): World
Creates a world.
Parameters
gravity?:Vector3— The gravity vector. Default is no gravity.
Returns
World— The world.
NewDebugDraw(data: DebugDrawCallbacks): DebugDraw
Creates a debug draw to register with {@link World.SetDebugDraw}. Its callbacks run in the script instance that created it; call {@link DebugDraw.Destroy} when it is no longer needed.
Parameters
data:DebugDrawCallbacks— The flags and the drawing callbacks.
Returns
DebugDraw— The debug draw.
NewPolygonShape(): PolygonShape
Creates an empty polygon shape. Give it vertices with {@link PolygonShape.Set} or {@link PolygonShape.SetAsBox}.
Returns
PolygonShape— The shape.
NewCircleShape(): CircleShape
Creates a circle shape with a radius of 0.
Returns
CircleShape— The shape.
NewChainShape(): ChainShape
Creates an empty chain shape. Give it vertices with {@link ChainShape.CreateLoop} or {@link ChainShape.CreateChain}.
Returns
ChainShape— The shape.
NewEdgeShape(): EdgeShape
Creates an edge shape. Give it vertices with {@link EdgeShape.SetTwoSided} or {@link EdgeShape.SetOneSided}.
Returns
EdgeShape— The shape.
b2LinearStiffness(frequencyHertz: number, dampingRatio: number, bodyA: Body, bodyB: Body): LuaMultiReturn<[ stiffness: number, damping: number ]>
Computes linear stiffness and damping from a frequency and a damping ratio.
Parameters
frequencyHertz:number— The frequency in hertz.dampingRatio:number— The damping ratio.bodyA:Body— The first body.bodyB:Body— The second body.
Returns
LuaMultiReturn<[ stiffness: number, damping: number ]>—stiffnessanddamping.
b2AngularStiffness(frequencyHertz: number, dampingRatio: number, bodyA: Body, bodyB: Body): LuaMultiReturn<[ stiffness: number, damping: number ]>
Computes angular stiffness and damping from a frequency and a damping ratio.
Parameters
frequencyHertz:number— The frequency in hertz.dampingRatio:number— The damping ratio.bodyA:Body— The first body.bodyB:Body— The second body.
Returns
LuaMultiReturn<[ stiffness: number, damping: number ]>—stiffnessanddamping.
InitializeRevoluteJointDef(bodyA: Body, bodyB: Body, anchor: Vector3): RevoluteJointDef
Fills a revolute joint definition: the bodies, the local anchors and the reference angle, from a world anchor.
Parameters
bodyA:Body— The first body.bodyB:Body— The second body.anchor:Vector3— The world anchor.
Returns
RevoluteJointDef— The definition.
InitializePrismaticJointDef(bodyA: Body, bodyB: Body, anchor: Vector3, axis: Vector3): PrismaticJointDef
Fills a prismatic joint definition: the bodies, the local anchors, the axis and the reference angle, from a world anchor and a unit world axis.
Parameters
bodyA:Body— The first body.bodyB:Body— The second body.anchor:Vector3— The world anchor.axis:Vector3— The unit world axis.
Returns
PrismaticJointDef— The definition.
InitializeDistanceJointDef(bodyA: Body, bodyB: Body, anchorA: Vector3, anchorB: Vector3): DistanceJointDef
Fills a distance joint definition: the bodies, the local anchors and the rest length, from world anchors. The minimum and maximum lengths are set to the rest length.
Parameters
bodyA:Body— The first body.bodyB:Body— The second body.anchorA:Vector3— The world anchor on bodyA.anchorB:Vector3— The world anchor on bodyB.
Returns
DistanceJointDef— The definition.
InitializePulleyJointDef(bodyA: Body, bodyB: Body, groundAnchorA: Vector3, groundAnchorB: Vector3, anchorA: Vector3, anchorB: Vector3, ratio: number): PulleyJointDef
Fills a pulley joint definition: the bodies, the anchors, the lengths and the ratio, from world anchors.
Parameters
bodyA:Body— The first body.bodyB:Body— The second body.groundAnchorA:Vector3— The world ground anchor for bodyA.groundAnchorB:Vector3— The world ground anchor for bodyB.anchorA:Vector3— The world anchor on bodyA.anchorB:Vector3— The world anchor on bodyB.ratio:number— The pulley ratio.
Returns
PulleyJointDef— The definition.
InitializeMouseJointDef(bodyA: Body, bodyB: Body): MouseJointDef
Fills a mouse joint definition with the two bodies.
Parameters
bodyA:Body— The first body.bodyB:Body— The body that tracks the target.
Returns
MouseJointDef— The definition.
InitializeGearJointDef(bodyA: Body, bodyB: Body, joint1: RevoluteJoint | PrismaticJoint, joint2: RevoluteJoint | PrismaticJoint): GearJointDef
Fills a gear joint definition with the two bodies and the two joints it connects.
Parameters
bodyA:Body— The first body.bodyB:Body— The second body.joint1:RevoluteJoint | PrismaticJoint— The first revolute or prismatic joint.joint2:RevoluteJoint | PrismaticJoint— The second revolute or prismatic joint.
Returns
GearJointDef— The definition.
InitializeWheelJointDef(bodyA: Body, bodyB: Body, anchor: Vector3, axis: Vector3): WheelJointDef
Fills a wheel joint definition: the bodies, the local anchors and the axis, from a world anchor and a world axis.
Parameters
bodyA:Body— The first body.bodyB:Body— The second body.anchor:Vector3— The world anchor.axis:Vector3— The world axis.
Returns
WheelJointDef— The definition.
InitializeWeldJointDef(bodyA: Body, bodyB: Body, anchor: Vector3): WeldJointDef
Fills a weld joint definition: the bodies, the local anchors and the reference angle, from a world anchor.
Parameters
bodyA:Body— The first body.bodyB:Body— The second body.anchor:Vector3— The world anchor.
Returns
WeldJointDef— The definition.
InitializeFrictionJointDef(bodyA: Body, bodyB: Body, anchor: Vector3): FrictionJointDef
Fills a friction joint definition: the bodies and the local anchors, from a world anchor.
Parameters
bodyA:Body— The first body.bodyB:Body— The second body.anchor:Vector3— The world anchor.
Returns
FrictionJointDef— The definition.
InitializeMotorJointDef(bodyA: Body, bodyB: Body): MotorJointDef
Fills a motor joint definition: the bodies and the offsets, from their current transforms.
Parameters
bodyA:Body— The first body.bodyB:Body— The second body.
Returns
MotorJointDef— The definition.
Variables
b2Shape.e_circle: 0
b2Shape.e_edge: 1
b2Shape.e_polygon: 2
b2Shape.e_chain: 3
b2BodyType.b2_staticBody: 0
Zero mass, zero velocity; may be moved by hand.
b2BodyType.b2_kinematicBody: 1
Zero mass, velocity set by the user, moved by the solver.
b2BodyType.b2_dynamicBody: 2
Positive mass, velocity determined by forces, moved by the solver.
b2JointType.e_unknownJoint: 0
b2JointType.e_revoluteJoint: 1
b2JointType.e_prismaticJoint: 2
b2JointType.e_distanceJoint: 3
b2JointType.e_pulleyJoint: 4
b2JointType.e_mouseJoint: 5
b2JointType.e_gearJoint: 6
b2JointType.e_wheelJoint: 7
b2JointType.e_weldJoint: 8
b2JointType.e_frictionJoint: 9
b2JointType.e_ropeJoint: 10
b2JointType.e_motorJoint: 11
b2Draw.e_shapeBit: 1
Draw shapes.
b2Draw.e_jointBit: 2
Draw joint connections.
b2Draw.e_aabbBit: 4
Draw axis-aligned bounding boxes.
b2Draw.e_pairBit: 8
Draw broad-phase pairs.
b2Draw.e_centerOfMassBit: 16
Draw the center of mass frame.
b2Manifold_Type.e_circles: 0
b2Manifold_Type.e_faceA: 1
b2Manifold_Type.e_faceB: 2
Types
type ShapeType = typeof b2Shape.e_circle | typeof b2Shape.e_edge | typeof b2Shape.e_polygon | typeof b2Shape.e_chain
type ShapeTable = CircleShapeTable | OneSidedEdgeShapeTable | TwoSidedEdgeShapeTable | BoxShapeTable | PolygonShapeTable | ChainShapeTable
type BoxShapeTable = AxisAlignedBoxShapeTable | OrientedBoxShapeTable
type ChainShapeTable = LoopChainShapeTable | OpenChainShapeTable
type BodyType = typeof b2BodyType.b2_staticBody | typeof b2BodyType.b2_kinematicBody | typeof b2BodyType.b2_dynamicBody
type ManifoldType = typeof b2Manifold_Type.e_circles | typeof b2Manifold_Type.e_faceA | typeof b2Manifold_Type.e_faceB
type JointType = typeof b2JointType.e_unknownJoint | typeof b2JointType.e_revoluteJoint | typeof b2JointType.e_prismaticJoint | typeof b2JointType.e_distanceJoint | typeof b2JointType.e_pulleyJoint | typeof b2JointType.e_mouseJoint | typeof b2JointType.e_gearJoint | typeof b2JointType.e_wheelJoint | typeof b2JointType.e_weldJoint | typeof b2JointType.e_frictionJoint | typeof b2JointType.e_ropeJoint | typeof b2JointType.e_motorJoint
type JointDef = RevoluteJointDef | PrismaticJointDef | DistanceJointDef | PulleyJointDef | MouseJointDef | GearJointDef | WheelJointDef | WeldJointDef | FrictionJointDef | MotorJointDef
World
World.SetDestructionListener(listener: DestructionListener | undefined)
Registers a destruction listener, replacing any earlier one.
Parameters
listener:DestructionListener | undefined— The callbacks, ornilto remove the listener.
World.SetContactListener(listener: ContactListener | undefined)
Registers a contact listener, replacing any earlier one. Its callbacks run in the script instance that registered it.
Parameters
listener:ContactListener | undefined— The callbacks, ornilto remove the listener.
World.SetDebugDraw(draw: DebugDraw | undefined)
Registers the debug draw that {@link World.DebugDraw} calls. The debug draw stays owned by the caller.
Parameters
draw:DebugDraw | undefined— The debug draw, ornilto remove it.
World.CreateBody(bodyDef?: BodyDef): Body
Creates a rigid body. Not allowed during callbacks.
Parameters
bodyDef?:BodyDef— The body definition. Default is a static body at the origin.
Returns
Body— The body.
World.DestroyBody(body: Body)
Destroys a body, with its fixtures and joints. Not allowed during callbacks.
Parameters
body:Body— The body.
World.CreateJoint(def: RevoluteJointDef): RevoluteJoint
Creates a revolute joint. Not allowed during callbacks.
Parameters
def:RevoluteJointDef— The joint definition.
Returns
RevoluteJoint— The joint.
World.CreateJoint(def: PrismaticJointDef): PrismaticJoint
Creates a prismatic joint. Not allowed during callbacks.
Parameters
def:PrismaticJointDef— The joint definition.
Returns
PrismaticJoint— The joint.
World.CreateJoint(def: DistanceJointDef): DistanceJoint
Creates a distance joint. Not allowed during callbacks.
Parameters
def:DistanceJointDef— The joint definition.
Returns
DistanceJoint— The joint.
World.CreateJoint(def: PulleyJointDef): PulleyJoint
Creates a pulley joint. Not allowed during callbacks.
Parameters
def:PulleyJointDef— The joint definition.
Returns
PulleyJoint— The joint.
World.CreateJoint(def: MouseJointDef): MouseJoint
Creates a mouse joint. Not allowed during callbacks.
Parameters
def:MouseJointDef— The joint definition.
Returns
MouseJoint— The joint.
World.CreateJoint(def: GearJointDef): GearJoint
Creates a gear joint. Not allowed during callbacks.
Parameters
def:GearJointDef— The joint definition.
Returns
GearJoint— The joint.
World.CreateJoint(def: WheelJointDef): WheelJoint
Creates a wheel joint. Not allowed during callbacks.
Parameters
def:WheelJointDef— The joint definition.
Returns
WheelJoint— The joint.
World.CreateJoint(def: WeldJointDef): WeldJoint
Creates a weld joint. Not allowed during callbacks.
Parameters
def:WeldJointDef— The joint definition.
Returns
WeldJoint— The joint.
World.CreateJoint(def: FrictionJointDef): FrictionJoint
Creates a friction joint. Not allowed during callbacks.
Parameters
def:FrictionJointDef— The joint definition.
Returns
FrictionJoint— The joint.
World.CreateJoint(def: MotorJointDef): MotorJoint
Creates a motor joint. Not allowed during callbacks.
Parameters
def:MotorJointDef— The joint definition.
Returns
MotorJoint— The joint.
World.CreateJoint(def: JointDef): Joint
Creates a joint whose kind is known only at run time. Not allowed during callbacks.
Parameters
def:JointDef— The joint definition.
Returns
Joint— The joint.
World.DestroyJoint(joint: Joint)
Destroys a joint. The bodies it connected may begin to collide. Not allowed during callbacks.
Parameters
joint:Joint— The joint.
World.Step(timeStep: number, velocityIterations: number, positionIterations: number)
Takes a time step: collision detection, integration and constraint solution. Contact listener callbacks run inside it.
Parameters
timeStep:number— The time to simulate. It should not vary.velocityIterations:number— Iterations of the velocity constraint solver.positionIterations:number— Iterations of the position constraint solver.
World.ClearForces()
Clears the force buffer on all bodies. Forces clear after each step unless {@link World.SetAutoClearForces} turned that off, for sub-stepping.
World.DebugDraw()
Calls the registered debug draw for the shapes and other debug data.
World.RayCast(callback: (this: void, fixture: Fixture, point: Vector3, normal: Vector3, fraction: number) => number, point1: Vector3, point2: Vector3)
Casts a ray against every fixture in its path. The ray ignores shapes that contain its start.
Parameters
callback:(this: void, fixture: Fixture, point: Vector3, normal: Vector3, fraction: number) => number— Called for each fixture hit. Return -1 to ignore the fixture, 0 to stop,fractionto clip the ray to this hit, or 1 to continue without clipping.point1:Vector3— The ray start.point2:Vector3— The ray end.
World.QueryAABB(callback: (this: void, fixture: Fixture) => boolean, aabb: AABB)
Finds every fixture whose AABB overlaps a box.
Parameters
callback:(this: void, fixture: Fixture) => boolean— Called for each fixture. Returntrueto continue the query,falseto stop it.aabb:AABB— The query box.
World.GetBodyList(): Body | undefined
Gets the first body in the world. Use {@link Body.GetNext} for the rest.
Returns
Body | undefined— The first body, ornilif there is none.
World.GetContactList(): Contact | undefined
Gets the first contact in the world. Use {@link Contact.GetNext} for the rest. Contacts come and go during a time step, so use a {@link ContactListener} not to miss any.
Returns
Contact | undefined— The first contact, ornilif there is none.
World.GetJointList(): Joint | undefined
Gets the first joint in the world. Use {@link Joint.GetNext} for the rest.
Returns
Joint | undefined— The first joint, ornilif there is none.
World.SetAllowSleeping(flag: boolean)
Enables or disables sleep.
Parameters
flag:boolean—trueallows bodies to sleep.
World.GetAllowSleeping(): boolean
Whether bodies may sleep.
Returns
boolean—trueif sleep is allowed.
World.SetWarmStarting(flag: boolean)
Enables or disables warm starting. For testing.
Parameters
flag:boolean—trueenables it.
World.GetWarmStarting(): boolean
Whether warm starting is enabled.
Returns
boolean—trueif it is.
World.SetContinuousPhysics(flag: boolean)
Enables or disables continuous physics. For testing.
Parameters
flag:boolean—trueenables it.
World.GetContinuousPhysics(): boolean
Whether continuous physics is enabled.
Returns
boolean—trueif it is.
World.SetSubStepping(flag: boolean)
Enables or disables single-stepped continuous physics. For testing.
Parameters
flag:boolean—trueenables it.
World.GetSubStepping(): boolean
Whether single-stepped continuous physics is enabled.
Returns
boolean—trueif it is.
World.GetProxyCount(): number
Gets the number of broad-phase proxies.
Returns
number— The count.
World.GetBodyCount(): number
Gets the number of bodies.
Returns
number— The count.
World.GetJointCount(): number
Gets the number of joints.
Returns
number— The count.
World.GetContactCount(): number
Gets the number of contacts, each with zero or more contact points.
Returns
number— The count.
World.GetTreeHeight(): number
Gets the height of the dynamic tree.
Returns
number— The height.
World.GetTreeBalance(): number
Gets the balance of the dynamic tree.
Returns
number— The balance.
World.GetTreeQuality(): number
Gets the quality metric of the dynamic tree. Smaller is better; the minimum is 1.
Returns
number— The quality.
World.SetGravity(gravity: Vector3)
Changes the global gravity vector.
Parameters
gravity:Vector3— The gravity.
World.GetGravity(): Vector3
Gets the global gravity vector.
Returns
Vector3— The gravity.
World.IsLocked(): boolean
Whether the world is in the middle of a time step.
Returns
boolean—trueif it is locked.
World.SetAutoClearForces(flag: boolean)
Sets whether forces clear automatically after each time step.
Parameters
flag:boolean—trueclears them.
World.GetAutoClearForces(): boolean
Whether forces clear automatically after each time step.
Returns
boolean—trueif they do.
World.ShiftOrigin(newOrigin: Vector3)
Shifts the world origin, for large worlds. Each body's position becomes
position - newOrigin.
Parameters
newOrigin:Vector3— The new origin relative to the old one.
World.GetProfile(): Profile
Gets the profile of the last step.
Returns
Profile— The times spent in each phase.
World.Dump()
Dumps the world to the log. Call it outside a time step. Not supported on Android or iOS.
World.Destroy()
Destroys the world with its bodies, fixtures, joints, contacts and listeners.
DestructionListener
DestructionListener.SayGoodbyeFixture?: (this: void, fixture: Fixture) => void
Called before the fixture is destroyed.
DestructionListener.SayGoodbyeJoint?: (this: void, joint: Joint) => void
Called before the joint is destroyed.
Fixture
Fixture.GetType(): ShapeType
Gets the type of the fixture's shape.
Returns
ShapeType— A {@link b2Shape} value.
Fixture.GetShape(): Shape
Gets a copy of the shape. Changing the copy does not change the fixture.
Returns
Shape— The shape copy.
Fixture.SetSensor(sensor: boolean)
Sets whether this fixture is a sensor.
Parameters
sensor:boolean—truemakes it a sensor.
Fixture.IsSensor(): boolean
Whether this fixture is a sensor (non-solid).
Returns
boolean—trueif it is a sensor.
Fixture.SetFilterData(filter: Filter)
Sets the contact filtering data. Contacts update at the next step when either body is active and awake. This calls {@link Fixture.Refilter}.
Parameters
filter:Filter— The filtering data.
Fixture.GetFilterData(): Filter
Gets the contact filtering data.
Returns
Filter— The filtering data.
Fixture.Refilter()
Re-establishes collision that a contact filter previously disabled.
Fixture.GetBody(): Body
Gets the body this fixture is attached to.
Returns
Body— The body.
Fixture.GetNext(): Fixture | undefined
Gets the next fixture in the body's fixture list.
Returns
Fixture | undefined— The next fixture, ornilat the end of the list.
Fixture.GetUserData(): object | undefined
Gets the application data.
Returns
object | undefined— The table, ornilif none is set.
Fixture.SetUserData(userdata: object | undefined)
Sets the application data.
Parameters
userdata:object | undefined— A table, ornilto clear it.
Fixture.TestPoint(point: Vector3): boolean
Tests a point for containment in this fixture.
Parameters
point:Vector3— A point in world coordinates.
Returns
boolean—trueif the point is inside.
Fixture.RayCast(input: RayCastInput, childIndex: number): RayCastOutput | undefined
Casts a ray against this fixture's shape.
Parameters
input:RayCastInput— The ray-cast input parameters.childIndex:number— The child shape index. 0️⃣ 0-based; passed tobox2dunchanged.
Returns
RayCastOutput | undefined— The hit, ornilif the ray misses.
Fixture.GetMassData(): MassData
Gets the mass data, from the density and the shape. The inertia is about the shape's origin. This may be expensive.
Returns
MassData— The mass data.
Fixture.GetDensity(): number
Gets the density.
Returns
number— The density.
Fixture.SetDensity(density: number)
Sets the density. This does not update the body's mass; call {@link Body.ResetMassData} for that.
Parameters
density:number— The density.
Fixture.GetFriction(): number
Gets the friction coefficient.
Returns
number— The friction.
Fixture.SetFriction(friction: number)
Sets the friction coefficient. Existing contacts keep their friction.
Parameters
friction:number— The friction.
Fixture.GetRestitution(): number
Gets the restitution coefficient.
Returns
number— The restitution.
Fixture.SetRestitution(restitution: number)
Sets the restitution coefficient. Existing contacts keep their restitution.
Parameters
restitution:number— The restitution.
Fixture.GetRestitutionThreshold(): number
Gets the restitution velocity threshold.
Returns
number— The threshold.
Fixture.SetRestitutionThreshold(threshold: number)
Sets the restitution velocity threshold. Existing contacts keep theirs.
Parameters
threshold:number— The threshold.
Fixture.GetAABB(childIndex: number): AABB
Gets the fixture's AABB, which may be enlarged or stale. For an exact box, compute it from the shape and the body transform.
Parameters
childIndex:number— The child shape index. 0️⃣ 0-based; passed tobox2dunchanged.
Returns
AABB— The box.
Fixture.Dump(bodyIndex: number)
Dumps this fixture to the log.
Parameters
bodyIndex:number— The index the dump gives the fixture's body. 0️⃣ 0-based; passed tobox2dunchanged.
Shape
Shape.Clone(): Shape
Copies the shape.
Returns
Shape— A new shape of the same type.
Shape.GetType(): ShapeType
Gets the type of this shape. Use it to tell which shape type the object is.
Returns
ShapeType— A {@link b2Shape} value.
Shape.GetChildCount(): number
Gets the number of child primitives.
Returns
number— The child count.
Shape.TestPoint(xf: Transform, p: Vector3): boolean
Tests a point for containment in this shape. This only works for convex shapes.
Parameters
xf:Transform— The shape's world transform.p:Vector3— A point in world coordinates.
Returns
boolean—trueif the point is inside.
Shape.RayCast(input: RayCastInput, transform: Transform, childIndex?: number): RayCastOutput | undefined
Casts a ray against a child shape.
Parameters
input:RayCastInput— The ray-cast input parameters.transform:Transform— The transform applied to the shape.childIndex?:number— The child shape index. Circle, polygon and edge shapes have one child and ignore it; a chain shape requires it. 0️⃣ 0-based; passed tobox2dunchanged.
Returns
RayCastOutput | undefined— The hit, ornilif the ray misses.
Shape.ComputeAABB(xf: Transform, childIndex?: number): AABB
Computes the axis-aligned bounding box of a child shape.
Parameters
xf:Transform— The world transform of the shape.childIndex?:number— The child shape index. Circle, polygon and edge shapes have one child and ignore it; a chain shape requires it. 0️⃣ 0-based; passed tobox2dunchanged.
Returns
AABB— The box.
Shape.ComputeMass(density: number): MassData
Computes the mass properties of this shape from its dimensions and density. The inertia is computed about the local origin.
Parameters
density:number— The density in kilograms per square meter.
Returns
MassData— The mass data.
Shape.GetRadius(): number
Gets the radius. For a polygon it is the polygon skin radius.
Returns
number— The radius.
Shape.SetRadius(radius: number)
Sets the radius.
Parameters
radius:number— The new radius.
Transform
Transform.p: Vector3
The position.
Transform.q: number
The rotation angle in radians.
RayCastInput
RayCastInput.p1: Vector3
RayCastInput.p2: Vector3
RayCastInput.maxFraction: number
RayCastOutput
RayCastOutput.normal: Vector3
RayCastOutput.fraction: number
AABB
AABB.lowerBound: Vector3
The lower vertex.
AABB.upperBound: Vector3
The upper vertex.
MassData
MassData.mass: number
The mass, usually in kilograms.
MassData.center: Vec2
The position of the center of mass relative to the shape origin. A plain {x, y} table.
MassData.I: number
The rotational inertia about the local origin.
Vec2
Vec2.x: number
Vec2.y: number
Filter
Filter.categoryBits: number
The collision category bits. Normally one bit is set.
Filter.maskBits: number
The categories this shape accepts for collision.
Filter.groupIndex: number
Objects in the same negative group never collide; in the same positive group they always collide. Zero means no group. A non-zero group wins over the mask bits.
Body
Body.CreateFixture(def: FixtureDef): Fixture
Creates a fixture from a definition and attaches it to this body. If the density is non-zero, the body's mass is updated. Contacts are not created until the next step. Not allowed during callbacks.
Parameters
def:FixtureDef— The fixture definition.
Returns
Fixture— The fixture.
Body.CreateFixture(shape: Shape | ShapeTable, density: number): Fixture
Creates a fixture from a shape and attaches it to this body. Use a {@link FixtureDef} to set friction, restitution, user data or filtering. Not allowed during callbacks.
Parameters
shape:Shape | ShapeTable— The shape. The fixture gets a copy.density:number— The shape density; zero for a static body.
Returns
Fixture— The fixture.
Body.DestroyFixture(fixture: Fixture)
Destroys a fixture, removing it from the broad-phase and destroying its contacts. A dynamic body's mass is adjusted if the fixture had positive density. Not allowed during callbacks.
Parameters
fixture:Fixture— The fixture.
Body.SetTransform(position: Vector3, angle?: number)
Sets the position of the body's origin and its rotation. This may cause non-physical behavior; contacts update at the next step.
Parameters
position:Vector3— The world position of the body's local origin.angle?:number— The world rotation in radians. Default is the current angle.
Body.GetTransform(): Transform
Gets the transform of the body's origin.
Returns
Transform— The transform.
Body.GetPosition(): Vector3
Gets the world position of the body's origin.
Returns
Vector3— The position.
Body.GetPositionRaw(): LuaMultiReturn<[ number, number ]>
Gets the world position of the body's origin as two numbers, with no
vector3 allocated.
Returns
LuaMultiReturn<[ number, number ]>—xandy.
Body.GetAngle(): number
Gets the angle.
Returns
number— The angle in radians.
Body.GetWorldCenter(): Vector3
Gets the world position of the center of mass.
Returns
Vector3— The position.
Body.GetLocalCenter(): Vector3
Gets the local position of the center of mass.
Returns
Vector3— The position.
Body.SetLinearVelocity(velocity: Vector3)
Sets the linear velocity of the center of mass.
Parameters
velocity:Vector3— The velocity.
Body.GetLinearVelocity(): Vector3
Gets the linear velocity of the center of mass.
Returns
Vector3— The velocity.
Body.SetAngularVelocity(omega: number)
Sets the angular velocity.
Parameters
omega:number— The angular velocity in radians per second.
Body.GetAngularVelocity(): number
Gets the angular velocity.
Returns
number— The angular velocity in radians per second.
Body.ApplyForce(force: Vector3, point: Vector3, wake: boolean)
Applies a force at a world point. Off the center of mass it also produces a torque.
Parameters
force:Vector3— The world force, usually in N.point:Vector3— The world position where it applies.wake:boolean—truealso wakes the body.
Body.ApplyForceToCenter(force: Vector3, wake: boolean)
Applies a force to the center of mass.
Parameters
force:Vector3— The world force, usually in N.wake:boolean—truealso wakes the body.
Body.ApplyTorque(torque: number, wake: boolean)
Applies a torque. This changes the angular velocity but not the linear velocity of the center of mass.
Parameters
torque:number— The torque about the z-axis, usually in N-m.wake:boolean—truealso wakes the body.
Body.ApplyLinearImpulse(impulse: Vector3, point: Vector3, wake: boolean)
Applies an impulse at a world point. This changes the velocity at once, and the angular velocity if the point is off the center of mass.
Parameters
impulse:Vector3— The world impulse, usually in N-s.point:Vector3— The world position where it applies.wake:boolean—truealso wakes the body.
Body.ApplyLinearImpulseToCenter(impulse: Vector3, wake: boolean)
Applies an impulse to the center of mass. This changes the velocity at once.
Parameters
impulse:Vector3— The world impulse, usually in N-s.wake:boolean—truealso wakes the body.
Body.ApplyAngularImpulse(impulse: number, wake: boolean)
Applies an angular impulse.
Parameters
impulse:number— The angular impulse in kgmm/s.wake:boolean—truealso wakes the body.
Body.GetMass(): number
Gets the total mass.
Returns
number— The mass, usually in kilograms.
Body.GetInertia(): number
Gets the rotational inertia about the local origin.
Returns
number— The inertia, usually in kg-m^2.
Body.ResetMassData()
Resets the mass properties to the sum of the fixtures' mass properties. Needed only after {@link Body.SetMassData} overrode them.
Body.GetMassData(): MassData
Gets the mass data.
Returns
MassData— The mass, inertia and center of the body.
Body.SetMassData(data: MassData)
Overrides the mass properties of the fixtures. This moves the center of mass, and has no effect on a body that is not dynamic.
Parameters
data:MassData— The mass properties.
Body.GetWorldPoint(localPoint: Vector3): Vector3
Converts a local point to world coordinates.
Parameters
localPoint:Vector3— A point relative to the body's origin.
Returns
Vector3— The point in world coordinates.
Body.GetWorldVector(localVector: Vector3): Vector3
Converts a local vector to world coordinates.
Parameters
localVector:Vector3— A vector fixed in the body.
Returns
Vector3— The vector in world coordinates.
Body.GetLocalPoint(worldPoint: Vector3): Vector3
Converts a world point to a point relative to the body's origin.
Parameters
worldPoint:Vector3— A point in world coordinates.
Returns
Vector3— The local point.
Body.GetLocalVector(worldVector: Vector3): Vector3
Converts a world vector to a local vector.
Parameters
worldVector:Vector3— A vector in world coordinates.
Returns
Vector3— The local vector.
Body.GetLinearVelocityFromLocalPoint(localPoint: Vector3): Vector3
Gets the world velocity of a local point.
Parameters
localPoint:Vector3— A point in local coordinates.
Returns
Vector3— The world velocity of the point.
Body.GetLinearVelocityFromWorldPoint(worldPoint: Vector3): Vector3
Gets the world velocity of a world point attached to this body.
Parameters
worldPoint:Vector3— A point in world coordinates.
Returns
Vector3— The world velocity of the point.
Body.SetLinearDamping(linearDamping: number)
Sets the linear damping.
Parameters
linearDamping:number— The damping.
Body.GetLinearDamping(): number
Gets the linear damping.
Returns
number— The damping.
Body.SetAngularDamping(angularDamping: number)
Sets the angular damping.
Parameters
angularDamping:number— The damping.
Body.GetAngularDamping(): number
Gets the angular damping.
Returns
number— The damping.
Body.SetGravityScale(scale: number)
Sets the gravity scale.
Parameters
scale:number— The scale.
Body.GetGravityScale(): number
Gets the gravity scale.
Returns
number— The scale.
Body.SetType(type: BodyType)
Sets the body type. This may change the mass and velocity.
Parameters
type:BodyType— A {@link b2BodyType} value.
Body.GetType(): BodyType
Gets the body type.
Returns
BodyType— A {@link b2BodyType} value.
Body.SetBullet(flag: boolean)
Sets whether the body is treated like a bullet for continuous collision detection.
Parameters
flag:boolean—truemakes it a bullet.
Body.IsBullet(): boolean
Whether the body is treated like a bullet for continuous collision detection.
Returns
boolean—trueif it is a bullet.
Body.SetSleepingAllowed(flag: boolean)
Sets whether the body may sleep. Disallowing sleep wakes the body.
Parameters
flag:boolean—falsekeeps the body awake.
Body.IsSleepingAllowed(): boolean
Whether the body may sleep.
Returns
boolean—trueif sleep is allowed.
Body.SetAwake(flag: boolean)
Wakes the body or puts it to sleep. A sleeping body costs very little CPU.
Parameters
flag:boolean—truewakes the body,falseputs it to sleep.
Body.IsAwake(): boolean
Whether the body is awake.
Returns
boolean—trueif the body is awake.
Body.SetEnabled(flag: boolean)
Enables or disables the body. A disabled body is not simulated, cannot be collided with or woken, and stays in the world. Its fixtures leave the broad-phase and its contacts are destroyed; its joints are implicitly disabled.
Parameters
flag:boolean—trueenables the body.
Body.IsEnabled(): boolean
Whether the body is enabled.
Returns
boolean—trueif the body is enabled.
Body.SetFixedRotation(flag: boolean)
Sets whether the body has fixed rotation. This resets the mass.
Parameters
flag:boolean—truefixes the rotation.
Body.IsFixedRotation(): boolean
Whether the body has fixed rotation.
Returns
boolean—trueif the rotation is fixed.
Body.GetNext(): Body | undefined
Gets the next body in the world's body list.
Returns
Body | undefined— The next body, ornilat the end of the list.
Body.GetFixtureList(): Fixture | undefined
Gets the first fixture attached to this body. Use {@link Fixture.GetNext} for the rest.
Returns
Fixture | undefined— The first fixture, ornilif the body has none.
Body.GetContactList(): Contact[]
Gets the contacts attached to this body. The list changes during the time step, so use a {@link ContactListener} not to miss collisions.
⚠️ The list is the body's own table, filled from index 1; a contact from an earlier, longer call stays past the end of the current list.
Returns
Contact[]— The contacts.
Body.GetJointList(): Joint[]
Gets the joints attached to this body.
⚠️ The list is the body's own table, filled from index 1; a joint from an earlier, longer call stays past the end of the current list.
Returns
Joint[]— The joints.
Body.GetUserData(): object | undefined
Gets the application data.
Returns
object | undefined— The table, ornilif none is set.
Body.SetUserData(data: object | undefined)
Sets the application data.
Parameters
data:object | undefined— A table, ornilto clear it.
Body.GetWorld(): World
Gets the world this body belongs to.
Returns
World— The world.
Body.Dump()
Dumps this body to the log.
FixtureDef
FixtureDef.shape: Shape | ShapeTable
The shape. The fixture gets a copy.
FixtureDef.userData?: object
Application data. Must be a table.
FixtureDef.friction?: number
The friction coefficient, usually from 0 to 1. Default is 0.2.
FixtureDef.restitution?: number
The restitution (elasticity), usually from 0 to 1. Default is 0.
FixtureDef.restitutionThreshold?: number
Collisions above this speed, in meters per second, bounce. Default is 1.
FixtureDef.density?: number
The density, usually in kilograms per square meter. Default is 0.
FixtureDef.isSensor?: boolean
A sensor collects contact information but never generates a collision response.
FixtureDef.filter?: Filter
Contact filtering data.
CircleShapeTable
CircleShapeTable.shape: typeof b2Shape.e_circle
CircleShapeTable.circle_radius: number
CircleShapeTable.circle_position?: Vector3
The center relative to the body origin. Default is the origin.
OneSidedEdgeShapeTable
OneSidedEdgeShapeTable.shape: typeof b2Shape.e_edge
OneSidedEdgeShapeTable.edge_two_sided?: false
OneSidedEdgeShapeTable.edge_v0: Vector3
The vertex that precedes the edge.
OneSidedEdgeShapeTable.edge_v1: Vector3
OneSidedEdgeShapeTable.edge_v2: Vector3
OneSidedEdgeShapeTable.edge_v3: Vector3
The vertex that follows the edge.
TwoSidedEdgeShapeTable
TwoSidedEdgeShapeTable.shape: typeof b2Shape.e_edge
TwoSidedEdgeShapeTable.edge_two_sided: true
TwoSidedEdgeShapeTable.edge_v1: Vector3
TwoSidedEdgeShapeTable.edge_v2: Vector3
AxisAlignedBoxShapeTable
AxisAlignedBoxShapeTable.shape: typeof b2Shape.e_polygon
AxisAlignedBoxShapeTable.box: true
AxisAlignedBoxShapeTable.box_hx: number
The half-width.
AxisAlignedBoxShapeTable.box_hy: number
The half-height.
AxisAlignedBoxShapeTable.box_center?: never
AxisAlignedBoxShapeTable.box_angle?: never
OrientedBoxShapeTable
OrientedBoxShapeTable.shape: typeof b2Shape.e_polygon
OrientedBoxShapeTable.box: true
OrientedBoxShapeTable.box_hx: number
The half-width.
OrientedBoxShapeTable.box_hy: number
The half-height.
OrientedBoxShapeTable.box_center: Vector3
The center in local coordinates.
OrientedBoxShapeTable.box_angle: number
The rotation in radians.
PolygonShapeTable
PolygonShapeTable.shape: typeof b2Shape.e_polygon
PolygonShapeTable.box?: false
PolygonShapeTable.polygon_vertices: Vector3[]
From 3 to 8 points; their convex hull is used.
LoopChainShapeTable
LoopChainShapeTable.shape: typeof b2Shape.e_chain
LoopChainShapeTable.chain_vertices: Vector3[]
LoopChainShapeTable.chain_loop: true
Closes the chain into a loop.
OpenChainShapeTable
OpenChainShapeTable.shape: typeof b2Shape.e_chain
OpenChainShapeTable.chain_vertices: Vector3[]
OpenChainShapeTable.chain_loop?: false
OpenChainShapeTable.chain_prev_vertex: Vector3
The vertex that connects to the start.
OpenChainShapeTable.chain_next_vertex: Vector3
The vertex that connects to the end.
Contact
Contact.GetNext(): Contact | undefined
Gets the next contact in the world's contact list.
Returns
Contact | undefined— The next contact, ornilat the end of the list.
Contact.GetManifold(): Manifold
Gets the local manifold.
Returns
Manifold— The manifold.
Contact.GetWorldManifold(): WorldManifold
Gets the world manifold.
Returns
WorldManifold— The manifold in world coordinates.
Contact.IsTouching(): boolean
Whether this contact is touching.
Returns
boolean—trueif the fixtures touch.
Contact.SetEnabled(flag: boolean)
Enables or disables this contact for the current time step (or
sub-step in continuous collisions). Use it inside PreSolve.
Parameters
flag:boolean—falsedisables the contact.
Contact.IsEnabled(): boolean
Whether this contact is enabled.
Returns
boolean—trueif the contact is enabled.
Contact.GetFixtureA(): Fixture
Gets fixture A.
Returns
Fixture— The fixture.
Contact.GetChildIndexA(): number
Gets the child primitive index for fixture A.
Returns
number— The index. 0️⃣ 0-based; passed tobox2dunchanged.
Contact.GetFixtureB(): Fixture
Gets fixture B.
Returns
Fixture— The fixture.
Contact.GetChildIndexB(): number
Gets the child primitive index for fixture B.
Returns
number— The index. 0️⃣ 0-based; passed tobox2dunchanged.
Contact.SetFriction(friction: number)
Overrides the default friction mixture. Call it in PreSolve; the value
persists until it is set or reset.
Parameters
friction:number— The friction.
Contact.GetFriction(): number
Gets the friction.
Returns
number— The friction.
Contact.ResetFriction()
Resets the friction mixture to the default value.
Contact.SetRestitution(restitution: number)
Overrides the default restitution mixture. Call it in PreSolve; the
value persists until it is set or reset.
Parameters
restitution:number— The restitution.
Contact.GetRestitution(): number
Gets the restitution.
Returns
number— The restitution.
Contact.ResetRestitution()
Resets the restitution to the default value.
Contact.SetRestitutionThreshold(threshold: number)
Overrides the default restitution velocity threshold mixture. Call it in
PreSolve; the value persists until it is set or reset.
Parameters
threshold:number— The threshold.
Contact.GetRestitutionThreshold(): number
Gets the restitution threshold.
Returns
number— The threshold.
Contact.ResetRestitutionThreshold()
Resets the restitution threshold to the default value.
Contact.SetTangentSpeed(speed: number)
Sets the desired tangent speed for a conveyor belt, in meters per second.
Parameters
speed:number— The speed.
Contact.GetTangentSpeed(): number
Gets the desired tangent speed, in meters per second.
Returns
number— The speed.
Manifold
Manifold.type: ManifoldType
Manifold.localPoint: Vector3
Usage depends on the manifold type.
Manifold.localNormal: Vector3
Not used for e_circles.
Manifold.pointCount: number
The number of manifold points.
Manifold.points: ManifoldPoint[]
The points of contact.
ManifoldPoint
ManifoldPoint.localPoint: Vector3
Usage depends on the manifold type.
ManifoldPoint.normalImpulse: number
The non-penetration impulse.
ManifoldPoint.tangentImpulse: number
The friction impulse.
ManifoldPoint.id: ContactID
Identifies the contact point between the two shapes.
ContactID
ContactID.cf: ContactFeature
ContactID.key: number
Used to compare contact ids quickly.
ContactFeature
ContactFeature.indexA: number
Feature index on shape A.
ContactFeature.indexB: number
Feature index on shape B.
ContactFeature.typeA: number
The feature type on shape A: 0 for a vertex, 1 for a face.
ContactFeature.typeB: number
The feature type on shape B: 0 for a vertex, 1 for a face.
WorldManifold
WorldManifold.normal: Vector3
World vector pointing from A to B.
WorldManifold.points: Vector3[]
World contact points.
WorldManifold.separations: number[]
A negative value indicates overlap, in meters.
Joint
Joint.GetType(): JointType
Gets the joint type.
Returns
JointType— A {@link b2JointType} value.
Joint.GetBodyA(): Body
Gets the first attached body.
Returns
Body— bodyA.
Joint.GetBodyB(): Body
Gets the second attached body.
Returns
Body— bodyB.
Joint.GetAnchorA(): Vector3
Gets the anchor on bodyA in world coordinates.
Returns
Vector3— The anchor.
Joint.GetAnchorB(): Vector3
Gets the anchor on bodyB in world coordinates.
Returns
Vector3— The anchor.
Joint.GetReactionForce(inv_dt: number): Vector3
Gets the reaction force on bodyB at the joint anchor.
Parameters
inv_dt:number— The inverse time step.
Returns
Vector3— The force in N.
Joint.GetReactionTorque(inv_dt: number): number
Gets the reaction torque on bodyB.
Parameters
inv_dt:number— The inverse time step.
Returns
number— The torque in N*m.
Joint.GetNext(): Joint | undefined
Gets the next joint in the world's joint list.
Returns
Joint | undefined— The next joint, ornilat the end of the list.
Joint.GetUserData(): object | undefined
Gets the application data.
Returns
object | undefined— The table, ornilif none is set.
Joint.SetUserData(userdata: object | undefined)
Sets the application data. This is the only way to attach it to a joint, since a joint definition carries none.
Parameters
userdata:object | undefined— A table, ornilto clear it.
Joint.IsEnabled(): boolean
Whether either attached body is enabled.
Returns
boolean—trueif one is.
Joint.GetCollideConnected(): boolean
Whether the attached bodies collide. Changing it has no effect on fixtures that already overlap.
Returns
boolean—trueif they collide.
Joint.Dump()
Dumps this joint to the log.
Joint.ShiftOrigin(newOrigin: Vector3)
Shifts the origin of any points stored in world coordinates.
Parameters
newOrigin:Vector3— The new origin relative to the old one.
ContactListener
ContactListener.BeginContact?: (this: void, contact: Contact) => void
Called when two fixtures begin to touch.
ContactListener.EndContact?: (this: void, contact: Contact) => void
Called when two fixtures stop touching.
ContactListener.PreSolve?: (this: void, contact: Contact, oldManifold: Manifold) => void
Called after a contact is updated and before it goes to the solver.
ContactListener.PostSolve?: (this: void, contact: Contact, impulse: ContactImpulse) => void
Called after the solver, with the impulses it applied.
ContactImpulse
ContactImpulse.normalImpulses: number[]
ContactImpulse.tangentImpulses: number[]
ContactImpulse.count: number
DebugDraw
DebugDraw.SetFlags(flags: number)
Sets the drawing flags.
Parameters
flags:number— A sum of {@link b2Draw} bits.
DebugDraw.GetFlags(): number
Gets the drawing flags.
Returns
number— A sum of {@link b2Draw} bits.
DebugDraw.ClearFlags(flags: number)
Clears flags from the current flags.
Parameters
flags:number— A sum of {@link b2Draw} bits.
DebugDraw.Destroy()
Frees the debug draw.
BodyDef
BodyDef.type?: BodyType
The body type. Default is b2_staticBody. A dynamic body with zero mass gets a mass of one.
BodyDef.position?: Vector3
The world position. Avoid creating bodies at the origin, where shapes overlap.
BodyDef.angle?: number
The world angle in radians.
BodyDef.linearVelocity?: Vector3
The linear velocity of the body's origin in world coordinates.
BodyDef.angularVelocity?: number
The angular velocity.
BodyDef.linearDamping?: number
Reduces the linear velocity. Units are 1/time.
BodyDef.angularDamping?: number
Reduces the angular velocity. Units are 1/time.
BodyDef.allowSleep?: boolean
false keeps the body from sleeping, at a CPU cost. Default is true.
BodyDef.awake?: boolean
Whether the body starts awake. Default is true.
BodyDef.fixedRotation?: boolean
Prevents rotation. Useful for characters.
BodyDef.bullet?: boolean
Prevents a fast dynamic body from tunneling through other moving bodies. Use it sparingly; it costs processing time.
BodyDef.enabled?: boolean
Whether the body starts enabled. Default is true.
BodyDef.userData?: object
Application data. Must be a table.
BodyDef.gravityScale?: number
Scales the gravity applied to this body. Default is 1.
RevoluteJointDef
interface RevoluteJointDef extends JointDefBase
RevoluteJointDef.type: typeof b2JointType.e_revoluteJoint
RevoluteJointDef.localAnchorA?: Vector3
The anchor relative to bodyA's origin.
RevoluteJointDef.localAnchorB?: Vector3
The anchor relative to bodyB's origin.
RevoluteJointDef.referenceAngle?: number
bodyB's angle minus bodyA's angle in the reference state, in radians.
RevoluteJointDef.enableLimit?: boolean
Enables the joint limit.
RevoluteJointDef.lowerAngle?: number
The lower angle limit in radians.
RevoluteJointDef.upperAngle?: number
The upper angle limit in radians.
RevoluteJointDef.enableMotor?: boolean
Enables the joint motor.
RevoluteJointDef.motorSpeed?: number
The desired motor speed, usually in radians per second.
RevoluteJointDef.maxMotorTorque?: number
The maximum motor torque, usually in N-m.
JointDefBase
JointDefBase.bodyA: Body
The first attached body.
JointDefBase.bodyB: Body
The second attached body.
JointDefBase.collideConnected?: boolean
true lets the attached bodies collide.
RevoluteJoint
interface RevoluteJoint extends Joint
RevoluteJoint.GetLocalAnchorA(): Vector3
Gets the anchor relative to bodyA's origin.
Returns
Vector3— The anchor.
RevoluteJoint.GetLocalAnchorB(): Vector3
Gets the anchor relative to bodyB's origin.
Returns
Vector3— The anchor.
RevoluteJoint.GetReferenceAngle(): number
Gets the reference angle.
Returns
number— The angle in radians.
RevoluteJoint.GetJointAngle(): number
Gets the current joint angle.
Returns
number— The angle in radians.
RevoluteJoint.GetJointSpeed(): number
Gets the current joint angular speed.
Returns
number— The speed in radians per second.
RevoluteJoint.IsLimitEnabled(): boolean
Whether the joint limit is enabled.
Returns
boolean—trueif it is.
RevoluteJoint.EnableLimit(flag: boolean)
Enables or disables the joint limit.
Parameters
flag:boolean—trueenables it.
RevoluteJoint.GetLowerLimit(): number
Gets the lower joint limit.
Returns
number— The limit in radians.
RevoluteJoint.GetUpperLimit(): number
Gets the upper joint limit.
Returns
number— The limit in radians.
RevoluteJoint.SetLimits(lower: number, upper: number)
Sets the joint limits.
Parameters
lower:number— The lower limit in radians.upper:number— The upper limit in radians.
RevoluteJoint.IsMotorEnabled(): boolean
Whether the joint motor is enabled.
Returns
boolean—trueif it is.
RevoluteJoint.EnableMotor(flag: boolean)
Enables or disables the joint motor.
Parameters
flag:boolean—trueenables it.
RevoluteJoint.SetMotorSpeed(speed: number)
Sets the motor speed.
Parameters
speed:number— The speed in radians per second.
RevoluteJoint.GetMotorSpeed(): number
Gets the motor speed.
Returns
number— The speed in radians per second.
RevoluteJoint.SetMaxMotorTorque(torque: number)
Sets the maximum motor torque.
Parameters
torque:number— The torque, usually in N-m.
RevoluteJoint.GetMaxMotorTorque(): number
Gets the maximum motor torque.
Returns
number— The torque, usually in N-m.
RevoluteJoint.GetMotorTorque(inv_dt: number): number
Gets the current motor torque.
Parameters
inv_dt:number— The inverse time step.
Returns
number— The torque in N*m.
PrismaticJointDef
interface PrismaticJointDef extends JointDefBase
PrismaticJointDef.type: typeof b2JointType.e_prismaticJoint
PrismaticJointDef.localAnchorA?: Vector3
The anchor relative to bodyA's origin.
PrismaticJointDef.localAnchorB?: Vector3
The anchor relative to bodyB's origin.
PrismaticJointDef.localAxisA?: Vector3
The translation unit axis in bodyA.
PrismaticJointDef.referenceAngle?: number
bodyB's angle minus bodyA's angle, in radians.
PrismaticJointDef.enableLimit?: boolean
Enables the joint limit.
PrismaticJointDef.lowerTranslation?: number
The lower translation limit, usually in meters.
PrismaticJointDef.upperTranslation?: number
The upper translation limit, usually in meters.
PrismaticJointDef.enableMotor?: boolean
Enables the joint motor.
PrismaticJointDef.maxMotorForce?: number
The maximum motor force, usually in N.
PrismaticJointDef.motorSpeed?: number
The desired motor speed, usually in meters per second.
PrismaticJoint
interface PrismaticJoint extends Joint
PrismaticJoint.GetLocalAnchorA(): Vector3
Gets the anchor relative to bodyA's origin.
Returns
Vector3— The anchor.
PrismaticJoint.GetLocalAnchorB(): Vector3
Gets the anchor relative to bodyB's origin.
Returns
Vector3— The anchor.
PrismaticJoint.GetLocalAxisA(): Vector3
Gets the joint axis relative to bodyA.
Returns
Vector3— The axis.
PrismaticJoint.GetReferenceAngle(): number
Gets the reference angle.
Returns
number— The angle in radians.
PrismaticJoint.GetJointTranslation(): number
Gets the current joint translation.
Returns
number— The translation, usually in meters.
PrismaticJoint.GetJointSpeed(): number
Gets the current joint translation speed.
Returns
number— The speed, usually in meters per second.
PrismaticJoint.IsLimitEnabled(): boolean
Whether the joint limit is enabled.
Returns
boolean—trueif it is.
PrismaticJoint.EnableLimit(flag: boolean)
Enables or disables the joint limit.
Parameters
flag:boolean—trueenables it.
PrismaticJoint.GetLowerLimit(): number
Gets the lower joint limit.
Returns
number— The limit, usually in meters.
PrismaticJoint.GetUpperLimit(): number
Gets the upper joint limit.
Returns
number— The limit, usually in meters.
PrismaticJoint.SetLimits(lower: number, upper: number)
Sets the joint limits.
Parameters
lower:number— The lower limit, usually in meters.upper:number— The upper limit, usually in meters.
PrismaticJoint.IsMotorEnabled(): boolean
Whether the joint motor is enabled.
Returns
boolean—trueif it is.
PrismaticJoint.EnableMotor(flag: boolean)
Enables or disables the joint motor.
Parameters
flag:boolean—trueenables it.
PrismaticJoint.SetMotorSpeed(speed: number)
Sets the motor speed.
Parameters
speed:number— The speed, usually in meters per second.
PrismaticJoint.GetMotorSpeed(): number
Gets the motor speed.
Returns
number— The speed, usually in meters per second.
PrismaticJoint.SetMaxMotorForce(force: number)
Sets the maximum motor force.
Parameters
force:number— The force, usually in N.
PrismaticJoint.GetMaxMotorForce(): number
Gets the maximum motor force.
Returns
number— The force, usually in N.
PrismaticJoint.GetMotorForce(inv_dt: number): number
Gets the current motor force.
Parameters
inv_dt:number— The inverse time step.
Returns
number— The force, usually in N.
DistanceJointDef
interface DistanceJointDef extends JointDefBase
DistanceJointDef.type: typeof b2JointType.e_distanceJoint
DistanceJointDef.localAnchorA?: Vector3
The anchor relative to bodyA's origin.
DistanceJointDef.localAnchorB?: Vector3
The anchor relative to bodyB's origin.
DistanceJointDef.length?: number
The rest length.
DistanceJointDef.minLength?: number
The minimum length.
DistanceJointDef.maxLength?: number
The maximum length. Must be at least the minimum length.
DistanceJointDef.stiffness?: number
The linear stiffness in N/m.
DistanceJointDef.damping?: number
The linear damping in N*s/m.
DistanceJoint
interface DistanceJoint extends Joint
DistanceJoint.GetLocalAnchorA(): Vector3
Gets the anchor relative to bodyA's origin.
Returns
Vector3— The anchor.
DistanceJoint.GetLocalAnchorB(): Vector3
Gets the anchor relative to bodyB's origin.
Returns
Vector3— The anchor.
DistanceJoint.GetLength(): number
Gets the rest length.
Returns
number— The length.
DistanceJoint.SetLength(length: number)
Sets the rest length, which Box2D clamps to a stable minimum.
Parameters
length:number— The length.
DistanceJoint.GetMinLength(): number
Gets the minimum length.
Returns
number— The length.
DistanceJoint.SetMinLength(minLength: number)
Sets the minimum length, which Box2D clamps to a stable minimum.
Parameters
minLength:number— The length.
DistanceJoint.GetMaxLength(): number
Gets the maximum length.
Returns
number— The length.
DistanceJoint.SetMaxLength(maxLength: number)
Sets the maximum length.
Parameters
maxLength:number— The length.
DistanceJoint.GetCurrentLength(): number
Gets the current length.
Returns
number— The length.
DistanceJoint.SetStiffness(stiffness: number)
Sets the linear stiffness.
Parameters
stiffness:number— The stiffness in N/m.
DistanceJoint.GetStiffness(): number
Gets the linear stiffness.
Returns
number— The stiffness in N/m.
DistanceJoint.SetDamping(damping: number)
Sets the linear damping.
Parameters
damping:number— The damping in N*s/m.
DistanceJoint.GetDamping(): number
Gets the linear damping.
Returns
number— The damping in N*s/m.
PulleyJointDef
interface PulleyJointDef extends JointDefBase
PulleyJointDef.type: typeof b2JointType.e_pulleyJoint
PulleyJointDef.groundAnchorA?: Vector3
The first ground anchor in world coordinates. It never moves.
PulleyJointDef.groundAnchorB?: Vector3
The second ground anchor in world coordinates. It never moves.
PulleyJointDef.localAnchorA?: Vector3
The anchor relative to bodyA's origin.
PulleyJointDef.localAnchorB?: Vector3
The anchor relative to bodyB's origin.
PulleyJointDef.lengthA?: number
The reference length of the segment attached to bodyA.
PulleyJointDef.lengthB?: number
The reference length of the segment attached to bodyB.
PulleyJointDef.ratio?: number
The pulley ratio, used to simulate a block-and-tackle.
PulleyJoint
interface PulleyJoint extends Joint
PulleyJoint.GetGroundAnchorA(): Vector3
Gets the first ground anchor.
Returns
Vector3— The anchor.
PulleyJoint.GetGroundAnchorB(): Vector3
Gets the second ground anchor.
Returns
Vector3— The anchor.
PulleyJoint.GetLengthA(): number
Gets the reference length of the segment attached to bodyA.
Returns
number— The length.
PulleyJoint.GetLengthB(): number
Gets the reference length of the segment attached to bodyB.
Returns
number— The length.
PulleyJoint.GetRatio(): number
Gets the pulley ratio.
Returns
number— The ratio.
PulleyJoint.GetCurrentLengthA(): number
Gets the current length of the segment attached to bodyA.
Returns
number— The length.
PulleyJoint.GetCurrentLengthB(): number
Gets the current length of the segment attached to bodyB.
Returns
number— The length.
MouseJointDef
interface MouseJointDef extends JointDefBase
MouseJointDef.type: typeof b2JointType.e_mouseJoint
MouseJointDef.target?: Vector3
The initial world target point, assumed to coincide with the body anchor.
MouseJointDef.maxForce?: number
The maximum force used to move the body, usually a multiple of its weight.
MouseJointDef.stiffness?: number
The linear stiffness in N/m.
MouseJointDef.damping?: number
The linear damping in N*s/m.
MouseJoint
interface MouseJoint extends Joint
MouseJoint.SetTarget(target: Vector3)
Sets the target point.
Parameters
target:Vector3— The world target.
MouseJoint.GetTarget(): Vector3
Gets the target point.
Returns
Vector3— The world target.
MouseJoint.SetMaxForce(force: number)
Sets the maximum force.
Parameters
force:number— The force in N.
MouseJoint.GetMaxForce(): number
Gets the maximum force.
Returns
number— The force in N.
MouseJoint.SetStiffness(stiffness: number)
Sets the linear stiffness.
Parameters
stiffness:number— The stiffness in N/m.
MouseJoint.GetStiffness(): number
Gets the linear stiffness.
Returns
number— The stiffness in N/m.
MouseJoint.SetDamping(damping: number)
Sets the linear damping.
Parameters
damping:number— The damping in N*s/m.
MouseJoint.GetDamping(): number
Gets the linear damping.
Returns
number— The damping in N*s/m.
GearJointDef
interface GearJointDef extends JointDefBase
GearJointDef.type: typeof b2JointType.e_gearJoint
GearJointDef.joint1: RevoluteJoint | PrismaticJoint
The first revolute or prismatic joint.
GearJointDef.joint2: RevoluteJoint | PrismaticJoint
The second revolute or prismatic joint.
GearJointDef.ratio?: number
The gear ratio.
GearJoint
interface GearJoint extends Joint
GearJoint.GetJoint1(): Joint
Gets the first connected joint.
Returns
Joint— The joint.
GearJoint.GetJoint2(): Joint
Gets the second connected joint.
Returns
Joint— The joint.
GearJoint.SetRatio(ratio: number)
Sets the gear ratio.
Parameters
ratio:number— The ratio.
GearJoint.GetRatio(): number
Gets the gear ratio.
Returns
number— The ratio.
WheelJointDef
interface WheelJointDef extends JointDefBase
WheelJointDef.type: typeof b2JointType.e_wheelJoint
WheelJointDef.localAnchorA?: Vector3
The anchor relative to bodyA's origin.
WheelJointDef.localAnchorB?: Vector3
The anchor relative to bodyB's origin.
WheelJointDef.localAxisA?: Vector3
The translation axis in bodyA.
WheelJointDef.enableLimit?: boolean
Enables the joint limit.
WheelJointDef.lowerTranslation?: number
The lower translation limit, usually in meters.
WheelJointDef.upperTranslation?: number
The upper translation limit, usually in meters.
WheelJointDef.enableMotor?: boolean
Enables the joint motor.
WheelJointDef.maxMotorTorque?: number
The maximum motor torque, usually in N-m.
WheelJointDef.motorSpeed?: number
The desired motor speed in radians per second.
WheelJointDef.stiffness?: number
The suspension stiffness, typically in N/m.
WheelJointDef.damping?: number
The suspension damping, typically in N*s/m.
WheelJoint
interface WheelJoint extends Joint
WheelJoint.GetLocalAnchorA(): Vector3
Gets the anchor relative to bodyA's origin.
Returns
Vector3— The anchor.
WheelJoint.GetLocalAnchorB(): Vector3
Gets the anchor relative to bodyB's origin.
Returns
Vector3— The anchor.
WheelJoint.GetLocalAxisA(): Vector3
Gets the joint axis relative to bodyA.
Returns
Vector3— The axis.
WheelJoint.GetJointTranslation(): number
Gets the current joint translation.
Returns
number— The translation, usually in meters.
WheelJoint.GetJointLinearSpeed(): number
Gets the current joint linear speed.
Returns
number— The speed, usually in meters per second.
WheelJoint.GetJointAngle(): number
Gets the current joint angle.
Returns
number— The angle in radians.
WheelJoint.GetJointAngularSpeed(): number
Gets the current joint angular speed.
Returns
number— The speed in radians per second.
WheelJoint.IsLimitEnabled(): boolean
Whether the joint limit is enabled.
Returns
boolean—trueif it is.
WheelJoint.EnableLimit(flag: boolean)
Enables or disables the joint translation limit.
Parameters
flag:boolean—trueenables it.
WheelJoint.GetLowerLimit(): number
Gets the lower joint translation limit.
Returns
number— The limit, usually in meters.
WheelJoint.GetUpperLimit(): number
Gets the upper joint translation limit.
Returns
number— The limit, usually in meters.
WheelJoint.SetLimits(lower: number, upper: number)
Sets the joint translation limits.
Parameters
lower:number— The lower limit, usually in meters.upper:number— The upper limit, usually in meters.
WheelJoint.IsMotorEnabled(): boolean
Whether the joint motor is enabled.
Returns
boolean—trueif it is.
WheelJoint.EnableMotor(flag: boolean)
Enables or disables the joint motor.
Parameters
flag:boolean—trueenables it.
WheelJoint.SetMotorSpeed(speed: number)
Sets the motor speed.
Parameters
speed:number— The speed, usually in radians per second.
WheelJoint.GetMotorSpeed(): number
Gets the motor speed.
Returns
number— The speed, usually in radians per second.
WheelJoint.SetMaxMotorTorque(torque: number)
Sets the maximum motor torque.
Parameters
torque:number— The torque, usually in N-m.
WheelJoint.GetMaxMotorTorque(): number
Gets the maximum motor torque.
Returns
number— The torque, usually in N-m.
WheelJoint.GetMotorTorque(inv_dt: number): number
Gets the current motor torque.
Parameters
inv_dt:number— The inverse time step.
Returns
number— The torque, usually in N-m.
WheelJoint.SetStiffness(stiffness: number)
Sets the spring stiffness.
Parameters
stiffness:number— The stiffness, typically in N/m.
WheelJoint.GetStiffness(): number
Gets the spring stiffness.
Returns
number— The stiffness, typically in N/m.
WheelJoint.SetDamping(damping: number)
Sets the spring damping.
Parameters
damping:number— The damping, typically in N*s/m.
WheelJoint.GetDamping(): number
Gets the spring damping.
Returns
number— The damping, typically in N*s/m.
WeldJointDef
interface WeldJointDef extends JointDefBase
WeldJointDef.type: typeof b2JointType.e_weldJoint
WeldJointDef.localAnchorA?: Vector3
The anchor relative to bodyA's origin.
WeldJointDef.localAnchorB?: Vector3
The anchor relative to bodyB's origin.
WeldJointDef.referenceAngle?: number
bodyB's angle minus bodyA's angle in the reference state, in radians.
WeldJointDef.stiffness?: number
The rotational stiffness in N*m. 0 disables softness.
WeldJointDef.damping?: number
The rotational damping in Nms.
WeldJoint
interface WeldJoint extends Joint
WeldJoint.GetLocalAnchorA(): Vector3
Gets the anchor relative to bodyA's origin.
Returns
Vector3— The anchor.
WeldJoint.GetLocalAnchorB(): Vector3
Gets the anchor relative to bodyB's origin.
Returns
Vector3— The anchor.
WeldJoint.GetReferenceAngle(): number
Gets the reference angle.
Returns
number— The angle in radians.
WeldJoint.SetStiffness(stiffness: number)
Sets the stiffness.
Parameters
stiffness:number— The stiffness in N*m.
WeldJoint.GetStiffness(): number
Gets the stiffness.
Returns
number— The stiffness in N*m.
WeldJoint.SetDamping(damping: number)
Sets the damping.
Parameters
damping:number— The damping in Nms.
WeldJoint.GetDamping(): number
Gets the damping.
Returns
number— The damping in Nms.
FrictionJointDef
interface FrictionJointDef extends JointDefBase
FrictionJointDef.type: typeof b2JointType.e_frictionJoint
FrictionJointDef.localAnchorA?: Vector3
The anchor relative to bodyA's origin.
FrictionJointDef.localAnchorB?: Vector3
The anchor relative to bodyB's origin.
FrictionJointDef.maxForce?: number
The maximum friction force in N.
FrictionJointDef.maxTorque?: number
The maximum friction torque in N-m.
FrictionJoint
interface FrictionJoint extends Joint
FrictionJoint.GetLocalAnchorA(): Vector3
Gets the anchor relative to bodyA's origin.
Returns
Vector3— The anchor.
FrictionJoint.GetLocalAnchorB(): Vector3
Gets the anchor relative to bodyB's origin.
Returns
Vector3— The anchor.
FrictionJoint.SetMaxForce(force: number)
Sets the maximum friction force.
Parameters
force:number— The force in N.
FrictionJoint.GetMaxForce(): number
Gets the maximum friction force.
Returns
number— The force in N.
FrictionJoint.SetMaxTorque(torque: number)
Sets the maximum friction torque.
Parameters
torque:number— The torque in N*m.
FrictionJoint.GetMaxTorque(): number
Gets the maximum friction torque.
Returns
number— The torque in N*m.
MotorJointDef
interface MotorJointDef extends JointDefBase
MotorJointDef.type: typeof b2JointType.e_motorJoint
MotorJointDef.linearOffset?: Vector3
bodyB's position minus bodyA's position, in bodyA's frame, in meters.
MotorJointDef.angularOffset?: number
bodyB's angle minus bodyA's angle, in radians.
MotorJointDef.maxForce?: number
The maximum motor force in N.
MotorJointDef.maxTorque?: number
The maximum motor torque in N-m.
MotorJointDef.correctionFactor?: number
The position correction factor, from 0 to 1.
MotorJoint
interface MotorJoint extends Joint
MotorJoint.SetLinearOffset(linearOffset: Vector3)
Sets the target linear offset, in bodyA's frame.
Parameters
linearOffset:Vector3— The offset in meters.
MotorJoint.GetLinearOffset(): Vector3
Gets the target linear offset, in bodyA's frame.
Returns
Vector3— The offset in meters.
MotorJoint.SetAngularOffset(angularOffset: number)
Sets the target angular offset.
Parameters
angularOffset:number— The offset in radians.
MotorJoint.GetAngularOffset(): number
Gets the target angular offset.
Returns
number— The offset in radians.
MotorJoint.SetMaxForce(force: number)
Sets the maximum friction force.
Parameters
force:number— The force in N.
MotorJoint.GetMaxForce(): number
Gets the maximum friction force.
Returns
number— The force in N.
MotorJoint.SetMaxTorque(torque: number)
Sets the maximum friction torque.
Parameters
torque:number— The torque in N*m.
MotorJoint.GetMaxTorque(): number
Gets the maximum friction torque.
Returns
number— The torque in N*m.
MotorJoint.SetCorrectionFactor(factor: number)
Sets the position correction factor.
Parameters
factor:number— The factor, from 0 to 1.
MotorJoint.GetCorrectionFactor(): number
Gets the position correction factor.
Returns
number— The factor, from 0 to 1.
Profile
Profile.step: number
Profile.collide: number
Profile.solve: number
Profile.solveInit: number
Profile.solveVelocity: number
Profile.solvePosition: number
Profile.broadphase: number
Profile.solveTOI: number
DebugDrawCallbacks
DebugDrawCallbacks.flags?: number
What to draw: a sum of {@link b2Draw} bits.
DebugDrawCallbacks.DrawPolygon?: (this: void, vertices: Vec2[], color: Color) => void
Draws a closed polygon outline.
DebugDrawCallbacks.DrawSolidPolygon?: (this: void, vertices: Vec2[], color: Color) => void
Draws a filled polygon.
DebugDrawCallbacks.DrawCircle?: (this: void, center: Vec2, radius: number, color: Color) => void
Draws a circle outline.
DebugDrawCallbacks.DrawSolidCircle?: (this: void, center: Vec2, radius: number, axis: Vec2, color: Color) => void
Draws a filled circle, with axis marking its rotation.
DebugDrawCallbacks.DrawSegment?: (this: void, p1: Vec2, p2: Vec2, color: Color) => void
Draws a line segment.
DebugDrawCallbacks.DrawTransform?: (this: void, xf: Transform) => void
Draws a transform frame.
DebugDrawCallbacks.DrawPoint?: (this: void) => void
Accepted, but never called: the extension's Draw::DrawPoint has an empty body.
Color
Color.r: number
Color.g: number
Color.b: number
Color.a: number
PolygonShape
interface PolygonShape extends Shape
PolygonShape.Clone(): PolygonShape
Copies the shape.
Returns
PolygonShape— A new polygon shape.
PolygonShape.Set(points: Vector3[])
Creates a convex hull from local points. The points may be reordered, and collinear points are kept, which can lead to poor stacking.
Parameters
points:Vector3[]— From 3 to 8 points.
PolygonShape.SetAsBox(hx: number, hy: number)
Makes an axis-aligned box centered on the local origin.
Parameters
hx:number— The half-width.hy:number— The half-height.
PolygonShape.SetAsBox(hx: number, hy: number, center: Vector3, angle: number)
Makes an oriented box.
Parameters
hx:number— The half-width.hy:number— The half-height.center:Vector3— The center of the box in local coordinates.angle:number— The rotation of the box in radians.
PolygonShape.Validate(): boolean
Validates convexity. This is a very time consuming operation.
Returns
boolean—trueif the polygon is valid.
PolygonShape.GetCentroid(): Vector3
Gets the centroid.
Returns
Vector3— The centroid.
PolygonShape.GetVertices(): Vector3[]
Gets the vertices.
Returns
Vector3[]— The vertices.
PolygonShape.GetNormals(): Vector3[]
Gets the edge normals.
Returns
Vector3[]— The normals.
PolygonShape.GetCount(): number
Gets the number of vertices.
Returns
number— The vertex count.
CircleShape
interface CircleShape extends Shape
CircleShape.Clone(): CircleShape
Copies the shape.
Returns
CircleShape— A new circle shape.
CircleShape.SetPosition(position: Vector3)
Sets the center relative to the body origin.
Parameters
position:Vector3— The center.
CircleShape.GetPosition(): Vector3
Gets the center relative to the body origin.
Returns
Vector3— The center.
ChainShape
interface ChainShape extends Shape
ChainShape.Clone(): ChainShape
Copies the shape.
Returns
ChainShape— A new chain shape.
ChainShape.RayCast(input: RayCastInput, transform: Transform, childIndex: number): RayCastOutput | undefined
Casts a ray against one segment of the chain.
Parameters
input:RayCastInput— The ray-cast input parameters.transform:Transform— The transform applied to the shape.childIndex:number— The segment index. 0️⃣ 0-based; passed tobox2dunchanged.
Returns
RayCastOutput | undefined— The hit, ornilif the ray misses.
ChainShape.ComputeAABB(xf: Transform, childIndex: number): AABB
Computes the axis-aligned bounding box of one segment of the chain.
Parameters
xf:Transform— The world transform of the shape.childIndex:number— The segment index. 0️⃣ 0-based; passed tobox2dunchanged.
Returns
AABB— The box.
ChainShape.Clear()
Clears all vertices.
ChainShape.CreateLoop(vertices: Vector3[])
Creates a loop, connecting the last vertex to the first.
Parameters
vertices:Vector3[]— The vertices, which are copied.
ChainShape.CreateChain(vertices: Vector3[], prevVertex: Vector3, nextVertex: Vector3)
Creates a chain with ghost vertices that connect it to other chains.
Parameters
vertices:Vector3[]— The vertices, which are copied.prevVertex:Vector3— The vertex of the previous chain that connects to the start.nextVertex:Vector3— The vertex of the next chain that connects to the end.
ChainShape.GetChildEdge(index: number): EdgeShape
Gets one segment of the chain as an edge.
Parameters
index:number— The segment index. 0️⃣ 0-based; passed tobox2dunchanged.
Returns
EdgeShape— The segment.
ChainShape.GetVertices(): Vector3[]
Gets the vertices.
Returns
Vector3[]— The vertices.
ChainShape.GetNextVertex(): Vector3
Gets the ghost vertex after the end.
Returns
Vector3— The vertex.
ChainShape.GetPrevVertex(): Vector3
Gets the ghost vertex before the start.
Returns
Vector3— The vertex.
ChainShape.GetCount(): number
Gets the number of vertices.
Returns
number— The vertex count.
EdgeShape
interface EdgeShape extends Shape
EdgeShape.Clone(): EdgeShape
Copies the shape.
Returns
EdgeShape— A new edge shape.
EdgeShape.SetOneSided(v0: Vector3, v1: Vector3, v2: Vector3, v3: Vector3)
Makes the edge part of a sequence. v0 precedes the edge and v3
follows it; they smooth movement across junctions. The collision becomes
one-sided, with the normal pointing right when looking from v1 to v2.
Parameters
v0:Vector3— The vertex before the edge.v1:Vector3— The edge start.v2:Vector3— The edge end.v3:Vector3— The vertex after the edge.
EdgeShape.SetTwoSided(v1: Vector3, v2: Vector3)
Makes the edge isolated. The collision is two-sided.
Parameters
v1:Vector3— The edge start.v2:Vector3— The edge end.
EdgeShape.GetVertex0(): Vector3
Gets the vertex before the edge.
Returns
Vector3— The vertex.
EdgeShape.GetVertex1(): Vector3
Gets the edge start.
Returns
Vector3— The vertex.
EdgeShape.GetVertex2(): Vector3
Gets the edge end.
Returns
Vector3— The vertex.
EdgeShape.GetVertex3(): Vector3
Gets the vertex after the edge.
Returns
Vector3— The vertex.
EdgeShape.IsOneSided(): boolean
Whether the edge collides on one side only.
Returns
boolean—trueif the edge is one-sided.