Body

Interactornape.phys.Body (final class)

Class representing a physics Rigid Body.

Instance Members

@private


nape
debugDraw: Bool

Set to disable debug drawing/

When true, this Body will not be drawn during debug draw operations unless specifically given as argument to Debug draw() method. @default true


nape
type: BodyType

Type of body.

This value can be changed even if Body is inside of a Space.


nape
isBullet: Bool

Mark object for continuous collisions against other dynamic Bodies

If true, then this Body will undergo continuous collisions with other dynamic Bodies. This flag has no effect for non-dynamic Bodies.

This flag should only be set for very fast, small moving dynamic bodies, and due to the way continuous collisions are resolved it is not wise to enable this for a large group of bodies that interact together as it will lead to visual stalling.
Bullets also do not play well when existing in a group with respect to continuous collisions against kinematic objects and may cause tunnelling against the kinematic. @default false


nape
disableCCD: Bool

Declare object should never be collided continuously

When performing continuous collisions, Nape will check both Bodies to see if either has opted-out of CCD. If either Body has this flag true, then no CCD will be performed for that pair. @default false


List of shapes owned by Body.

Appending a Shape to this list is equivalent to shape.body = this

@default []


nape
compound: Null<Compound>

Compound this Body belongs to.

If this Body belongs to a Compound, then the Compound 'owns' this Body and it is the Compound which would be added/removed from a Space rather than this Body.

@default null


Space this Body is assigned to.

When this Body is part of a Compound, this value is immutable.
When a Body is part of a Compound it is owned by that Compound and it is the Compound that is added/removed from a Space.


Set of active arbiters related to this Body.

This list is immutable.


nape
isSleeping: Bool

Whether this body is sleeping.

This value is immutable, In Nape you do not ever need to manually wake up a Body. It will always be done automatically without error.

To manually put a Body to sleep is against the very nature of Nape API and so is excluded from the core of Nape. If you really want to do this then you should make use of the nape-hacks module.


Set of constraints using this Body.

This list contains those constraints that are inside of a Space only.

This list is immutable.


nape
position: nape.geom.Vec2

Position of Body's origin in px.

This value can be set and is equivalent to: this.position.set(value)

Attempting to set this value on a static Body that is in a Space will result in a debug build error.

Please note that for kinematic objects, setting this value is equiavalent to 'teleporting' the object, and for normal movement you should be using the kinematic body's velocity.

@default (0,0)


nape
velocity: nape.geom.Vec2

Linear velocity of Body's origin in px/s.

This value can be set and is equivalent to: this.velocity.set(value)

A static body cannot have its velocity set.

@default (0,0)


nape
kinematicVel: nape.geom.Vec2

Additional kinematic velocity of Body in px/s.

A bodies 'kinematic' velocity is an added velocity bias used in all physics computations but that will not effect how the Body moves directly.

Even a static body can be given a kinematic velocity, and can be used for such things as giving a body of water a fluid-velocity for fluid drag computations.

@default (0,0)


nape
surfaceVel: nape.geom.Vec2

Additional surface velocity for Body in px/s.

A bodies 'surface' velocity is an added velocity bias that is rotated to match the angle of the contact surface used in contact physics and will not effect how the Body moves directly.

Even a static body can be given a surface velocity, and can be used for such things as conveyor belts (By setting the x-component of surfaceVel).

@default (0,0)


nape
force: nape.geom.Vec2

Accumulated force acting on body in px.kg/s/s

This value is not used internally for any physics computations.

You may set this property only on dynamic bodies.

@default (0,0)


nape
constraintVelocity: nape.geom.Vec3

This property represents the velocity seen by constraint physics.

You should not need to use this property unless writing your own constraints using the UserConstraint API.


nape
rotation: Float

Rotation of Body in clockwise rad.

Attempting to set this value on a static Body that is in a Space will result in a debug build error.

Please note that for kinematic objects, setting this value is equiavalent to 'teleporting' the object, and for normal movement you should be using the kinematic body's angularVel.

@default 0


nape
angularVel: Float

Angular velocity of Body in clockwise rad/s

A static body cannot have its angular velocity set.

@default 0


nape
kinAngVel: Float

Additional kinematic angular velocity of Body in rad/s.

A bodies 'kinematic' velocity is an added velocity bias used in all physics computations but that will not effect how the Body moves directly.

Even a static body can be given a kinematic velocity, and can be used for such things as giving a body of water a fluid-velocity for fluid drag computations.

@default 0


nape
torque: Float

Accumulated torque acting on body in px.px.kg/s/s

This value is not used internally for any physics computations.

You may set this property only on dynamic bodies.

@default 0


nape
bounds: nape.geom.AABB

Bounding box of Body in world space.

This value can be accessed even if there are no Shapes in the Body, but attempting to query its values whilst there are no Shapes will result in a debug build error.

This AABB is immutable.


nape
allowMovement: Bool

Whether dynamic Body is permitted to be moved by physics linearly.

When this field is false, no physics will be able to cause a change in the bodies linear velocity (It can still move, but only if you tell it to like a kinematic body).

@default true


nape
allowRotation: Bool

Whether dynamic Body is permitted to be rotated by physics.

When this field is false, no physics will be able to cause a change in the bodies angular velocity (It can still rotate, but only if you tell it to like a kinematic body).

@default true


nape
massMode: MassMode

Method of mass computation for Body.

This value will be set implicitly to FIXED when mass property is set.
Setting back to DEFAULT will then set mass implicitly back to the default computed mass.

@default MassMode.DEFAULT


nape
constraintMass: Float

Mass to be used for a Body in User built constraints.

This value is given as the inverse mass of the Body taking into account Body type (Static and Kinematic Bodies will have constraintMass of 0) as well as properties like allowMovement.


nape
mass: Float

Mass of the Body.

This value is computed by default based on the Body's Shape's areas and Material densities.
When massMode is DEFAULT, accessing this value for an empty Body will thus give an error as the value is undefined.

Setting this value will permit you to give a fixed mass to the Body implicitly changing the massMode to MassMode.FIXED


nape
gravMassMode: GravMassMode

Method of computing mass as seen by gravity.

This value will be implicitly set by modifying gravMass or gravMassScale properties.

@default GravMassMode.DEFAULT


nape
gravMass: Float

Mass used in gravity computations in a Space.

Setting this value will implicitly change the gravMassMode to FIXED.
Set to 0 to disable gravity for this Body.


nape
gravMassScale: Float

Mass scale used in computation of gravity for Body in Space.

Setting this value will implicitly change the gravMassMode to SCALED.
When set, the gravMass of Body will be computed as this scaling factor multiplied with the Body's mass.


nape
inertiaMode: InertiaMode

Method of computing Body moment of inertia.

This value will be set implicitly by modifying Body inertia property.

@default InertiaMode.DEFAULT


nape
constraintInertia: Float

Moment of inertia to be used in user defined Constraints.

This value is equal to the inverse inertia of the Body taking into account Body type (Static and Kinematic bodies will have constraintInertia of 0). As well as properties like allowRotation.


nape
inertia: Float

Moment of inertia of this Body.

Setting this value will implicitly change the inertiaMode to FIXED.


nape
localCOM: nape.geom.Vec2

Local centre of mass of Body.

This value can be accessed even if Body has no shapes, but attempting to query its values will result in a debug build error.

This Vec2 is immutable.


nape
worldCOM: nape.geom.Vec2

World centre of mass of Body.

This value can be accessed even if Body has no shapes, but attempting to query its values will result in a debug build error.

This Vec2 is immutable.


nape
integrate(deltaTime: Float): Body

Integrate body forward in time, taking only velocities into account.

Name Type Description
deltaTime Float The time to integrate body by. This value may be negative to integrate back in time.
Returns Description
Body A refernce to 'this' Body

nape
isStatic(): Bool

Fast equivalent to body.type == BodyType.STATIC

Returns Description
Bool True if body is Static.

nape
isDynamic(): Bool

Fast equivalent to body.type == BodyType.DYNAMIC

Returns Description
Bool True if body is Dynamic.

nape
isKinematic(): Bool

Fast equivalent to body.type == BodyType.KINEMATIC

Returns Description
Bool True if body is Kinematic.

nape
copy(): Body

Construct an exact copy of this Body.

All properties will be exactly copied, with Shapes also being copied with the copied Body's and Shape's userData objects being assigned the same fields as the existing ones with values copied over by reference for object types.

Returns Description
Body A copy of this Body.

nape
setVelocityFromTarget(targetPosition: nape.geom.Vec2, targetRotation: Float, deltaTime: Float): Body

Set velocities to achieve desired position at end of time step.

This function is a utility to help with animating kinematic bodies. Kinematic bodies should be moved through velocity, but it is often easier to think in terms of position.

This method will set linear and angular velocities so that the target position/rotation is achieved at end of time step.

Name Type Description
targetPosition nape.geom.Vec2 The target position for Body.
targetRotation Float The target rotation for Body.
deltaTime Float The time step for next call to space.step().
Returns
Body

nape
connectedBodies(?depth: Int = -1, ?output: BodyList = null): BodyList

Compute set of bodies connected via constraints.

Only constraints that are inside of a Space will be considered the same way that the body's constraints list only tracks constraints that are part of a simulation.

Name Type Default Description
depth Int -1 Control the depth limit of the graph search. Negative values indicate an unlimited search. A depth value of 0 would cause only the current Body to be returned. (default -1)
output BodyList null An optional list to append results to, if left as null then a new list is created.
Returns Description
BodyList A list of the connected bodies up to the given graph depth.

nape
interactingBodies(?type: nape.callbacks.InteractionType = null, ?depth: Int = -1, ?output: BodyList = null): BodyList

Compute set of bodies interacting with this body.

Name Type Default Description
type nape.callbacks.InteractionType null When not equal to null, this parameter controls what sort of interaction we permit in the search.
depth Int -1 Control the depth limit of the graph search. Negative values indicate an unlimited search. A depth value of 0 would cause only the current Body to be returned. (default -1)
output BodyList null An optional list to append results to, if left as null then a new list is created.
Returns Description
BodyList A list of the interacting bodies up to the given graph depth.

nape
crushFactor(): Float

Determine how much this body is being crushed.

This is an approximate value, computed as: crushFactor = (sum(magnitude(impulse)) - magnitude(sum(impulse))) / mass

In this way, it is a mass and time step invariant value which is 0 when all impulses are acting on body in the same direction, and has maximum value when impulses act in opposing directions 'crushing' the Body.

Returns Description
Float A positive value representing an approximation to how much the body is being crushed.

nape
localPointToWorld(point: nape.geom.Vec2, ?weak: Bool = false): nape.geom.Vec2

Transform a point from Body's local coordinates to world coordinates.

Name Type Default Description
point nape.geom.Vec2 The point to transform.
weak Bool false If true the returned Vec2 will be automatically released back to object pool when used as an argument to a Nape function. (default false)
Returns Description
nape.geom.Vec2 The result of the transformation.

nape
worldPointToLocal(point: nape.geom.Vec2, ?weak: Bool = false): nape.geom.Vec2

Transform a point from world coordinates to Body's local coordinates.

Name Type Default Description
point nape.geom.Vec2 The point to transform.
weak Bool false If true the returned Vec2 will be automatically released back to object pool when used as an argument to a Nape function. (default false)
Returns Description
nape.geom.Vec2 The result of the transformation.

nape
localVectorToWorld(vector: nape.geom.Vec2, ?weak: Bool = false): nape.geom.Vec2

Transform vector from Body's local coordinates into world coordinates.

Name Type Default Description
vector nape.geom.Vec2 The vector to transform.
weak Bool false If true the returned Vec2 will be automatically released back to object pool when used as an argument to a Nape function. (default false)
Returns Description
nape.geom.Vec2 The result of the transformation.

nape
worldVectorToLocal(vector: nape.geom.Vec2, ?weak: Bool = false): nape.geom.Vec2

Transform vector from world coordinates to Body's local coordinates

Name Type Default Description
vector nape.geom.Vec2 The vector to transform.
weak Bool false If true the returned Vec2 will be automatically released back to object pool when used as an argument to a Nape function. (default false)
Returns Description
nape.geom.Vec2 The result of the transformation.

nape
applyImpulse(impulse: nape.geom.Vec2, ?pos: nape.geom.Vec2 = null, ?sleepable: Bool = false): Body

Apply impulse to a point on Body.

If position argument is not given, then body.position is assumed so that impulse is applied at centre of Body.

Name Type Default Description
impulse nape.geom.Vec2 The impulse to apply given in world coordinates.
pos nape.geom.Vec2 null The position to apply impulse given in world coordinates. (default body.position)
sleepable Bool false This parameter can be set to true, in the case that you are constantly applying an impulse which is dependent only on the position/velocity of the body meaning that application of this impulse does not need to prevent the object from sleeping. When true, and the body is sleeping, this method call will not apply any impulse. (default false).
Returns
Body

nape
applyAngularImpulse(impulse: Float, ?sleepable: Bool = false): Body

Apply a pure angular impulse to Body.

Name Type Default Description
impulse Float The angular impulse to apply.
sleepable Bool false This parameter can be set to true, in the case that you are constantly applying an impulse which is dependent only on the position/velocity of the body meaning that application of this impulse does not need to prevent the object from sleeping. When true, and the body is sleeping, this method call will not apply any impulse. (default false).
Returns
Body

nape
translateShapes(translation: nape.geom.Vec2): Body

Translate each shape in local coordinates.

This operation does not effect the Body's position, but the position of the shapes 'inside' of the Body.

Name Type Description
translation nape.geom.Vec2 The local translation to apply to Shapes.
Returns Description
Body A reference to this Body.

nape
rotateShapes(angle: Float): Body

Rotate each shape in local coordinates.

This operation does not effect the Body's rotation, but rotates each of the shapes 'inside' of the Body.

Name Type Description
angle Float The angle to rotate shapes by in clockwise radians.
Returns Description
Body A reference to this Body.

nape
scaleShapes(scaleX: Float, scaleY: Float): Body

Scale each shape in local coordinates.

This operation does not affect the Body itself, but affects each Shape 'inside' of the Body instead.

Name Type Description
scaleX Float The x-coordinate factor of scaling.
scaleY Float The y-coordinate factor of scaling.
Returns Description
Body A reference to this Body.

nape
transformShapes(matrix: nape.geom.Mat23): Body

Transform each shape in local coordiantes.

This operation does not affect the Body itself, but affects each Shape 'inside' of the Body instead.

Name Type Description
matrix nape.geom.Mat23 The transformation matrix to apply to each Shape.
Returns Description
Body A reference to this Body.

nape
align(): Body

Align rigid body so that its origin is also its centre of mass.

This operation will both translate the Shapes inside of the Body, as well as translating the Body itself so that its 'apparent' position has not been modified.

Alignment of Rigid bodies is necessary for dynamic bodies so that they will interact and rotate as expected.

Simple Body's created with a single Polygon.box() or basic Circle will already be aligned.

Returns Description
Body A reference to this Body.

nape
rotate(centre: nape.geom.Vec2, angle: Float): Body

Rotate body about about given point.

Please note that this method is equivalent to teleporting the body, the same way direct manipulation of position and rotation is.

Name Type Description
centre nape.geom.Vec2 The centre of rotation in world coordinates.
angle Float The angle to rotate body by in clockwise radians.
Returns Description
Body A reference to this Body.

nape
setShapeMaterials(material: Material): Body

Set material of all shapes.

Equivalent to: body.shapes.foreach(function (shape) shape.material = material)

Name Type Description
material Material The material to set Shape's material to.
Returns Description
Body A reference to this Body.

nape
setShapeFilters(filter: nape.dynamics.InteractionFilter): Body

Set interaction filter of all shapes.

Equivalent to: body.shapes.foreach(function (shape) shape.filter = filter)

Name Type Description
filter nape.dynamics.InteractionFilter The filter to set Shape's filter to.
Returns Description
Body A reference to this Body.

nape
setShapeFluidProperties(fluidProperties: FluidProperties): Body

Set fluidProperties of all shapes.

Equivalent to: body.shapes.foreach(function (shape) shape.fluidProperties = fluidProperties)

Name Type Description
fluidProperties FluidProperties The fluidProperties to set Shape's fluidProperties to.
Returns Description
Body A reference to this Body.

nape
normalImpulse(?body: Body = null, ?freshOnly: Bool = false): nape.geom.Vec3

Evaluate sum effect of all normal contact impulses on Body.

If the body argument is non-null, then only impulses between 'this' and the given Body will be considered.

Name Type Default Description
body Body null The Body to restrict consideration of impulses with. (default null)
freshOnly Bool false If true, then only 'new' contact points will be considered. (default false)
Returns Description
nape.geom.Vec3 The summed effect of impulses acting on Body.

nape
tangentImpulse(?body: Body = null, ?freshOnly: Bool = false): nape.geom.Vec3

Evaluate sum effect of all tangent contact impulses on Body.

If the body argument is non-null, then only impulses between 'this' and the given Body will be considered.

Name Type Default Description
body Body null The Body to restrict consideration of impulses with. (default null)
freshOnly Bool false If true, then only 'new' contact points will be considered. (default false)
Returns Description
nape.geom.Vec3 The summed effect of impulses acting on Body.

nape
totalContactsImpulse(?body: Body = null, ?freshOnly: Bool = false): nape.geom.Vec3

Evaluate sum effect of all contact impulses on Body.

If the body argument is non-null, then only impulses between 'this' and the given Body will be considered.

Name Type Default Description
body Body null The Body to restrict consideration of impulses with. (default null)
freshOnly Bool false If true, then only 'new' contact points will be considered. (default false)
Returns Description
nape.geom.Vec3 The summed effect of impulses acting on Body.

nape
rollingImpulse(?body: Body = null, ?freshOnly: Bool = false): Float

Evaluate sum effect of all rolling friction contact impulses on Body.
<br/ If the body argument is non-null, then only impulses between 'this' and the given Body will be considered.

Name Type Default Description
body Body null The Body to restrict consideration of impulses with. (default null)
freshOnly Bool false If true, then only 'new' contact points will be considered. (default false)
Returns Description
Float The summed effect of impulses acting on Body.

nape
buoyancyImpulse(?body: Body = null): nape.geom.Vec3

Evaluate sum effect of all buoyancy impulses acting on Body.
<br/ If the body argument is non-null, then only impulses between 'this' and the given Body will be considered.

Name Type Default Description
body Body null The Body to restrict consideration of impulses with. (default null)
Returns Description
nape.geom.Vec3 The summed effect of impulses acting on Body.

nape
dragImpulse(?body: Body = null): nape.geom.Vec3

Evaluate sum effect of all fluid drag impulses acting on Body.
<br/ If the body argument is non-null, then only impulses between 'this' and the given Body will be considered.

Name Type Default Description
body Body null The Body to restrict consideration of impulses with. (default null)
Returns Description
nape.geom.Vec3 The summed effect of impulses acting on Body.

nape
totalFluidImpulse(?body: Body = null): nape.geom.Vec3

Evaluate sum effect of all fluid impulses acting on Body.
<br/ If the body argument is non-null, then only impulses between 'this' and the given Body will be considered.

Name Type Default Description
body Body null The Body to restrict consideration of impulses with. (default null)
Returns Description
nape.geom.Vec3 The summed effect of impulses acting on Body.

nape
constraintsImpulse(): nape.geom.Vec3

Evaluate sum effect of all constraint impulses on this Body.

Returns Description
nape.geom.Vec3 The summed effect of constraint impulses acting on Body.

nape
totalImpulse(?body: Body = null, ?freshOnly: Bool = false): nape.geom.Vec3

Evaluate sum effect of all impulses on Body.
<br/ If the body argument is non-null, then only impulses between 'this' and the given Body will be considered when evaluating interaction impulses.
Constraint impulses are not effected by the body argument.

Name Type Default Description
body Body null The Body to restrict consideration of impulses with. (default null)
freshOnly Bool false If true, then only 'new' contact points will be considered when evaluating contact impulses. (default false)
Returns Description
nape.geom.Vec3 The summed effect of impulses acting on Body.

nape
contains(point: nape.geom.Vec2): Bool

Determine if point is contained in Body.

Name Type Description
point nape.geom.Vec2 The point to test containment for in world coordinates.
Returns Description
Bool True if point is contained.

nape
toString(): String

@private

Returns
String

nape
new(?type: BodyType = null, ?position: nape.geom.Vec2 = null): Void

Construct a new Body.

Name Type Default Description
type BodyType null The type of Body to create. (default DYNAMIC)
position nape.geom.Vec2 null The initial position for object. (default (0,0))

Private Members

Metadata

Name Parameters
:final -