Class representing a physics Rigid Body.

Constructor

@:value({ position : null, type : null })new(?type:BodyType, ?position:Vec2)

Construct a new Body.

Parameters:

type

The type of Body to create. (default DYNAMIC)

position

The initial position for object. (default (0,0))

Returns:

The newly constructed Body.

Throws:

#

If position is non-null, and has been disposed of.

Variables

@:value(null)zpp_inner:ZPP_Body = null

@private

@:value(true)debugDraw:Bool = true

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.

type:BodyType

Type of body.

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

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.

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.

read onlyshapes:ShapeList

List of shapes owned by Body.

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

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.

space:Null<Space>

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.

read onlyarbiters:ArbiterList

Set of active arbiters related to this Body.

This list is immutable.

read onlyisSleeping: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.

read onlyconstraints:ConstraintList

Set of constraints using this Body.

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

This list is immutable.

position: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.

velocity: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.

kinematicVel: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.

surfaceVel: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).

force: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.

read onlyconstraintVelocity: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.

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.

angularVel:Float

Angular velocity of Body in clockwise rad/s

A static body cannot have its angular velocity set.

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.

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.

read onlybounds: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.

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).

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).

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.

read onlyconstraintMass: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.

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

gravMassMode:GravMassMode

Method of computing mass as seen by gravity.

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

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.

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.

inertiaMode:InertiaMode

Method of computing Body moment of inertia.

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

read onlyconstraintInertia: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.

inertia:Float

Moment of inertia of this Body.

Setting this value will implicitly change the inertiaMode to FIXED.

read onlylocalCOM: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.

read onlyworldCOM: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.

Methods

integrate(deltaTime:Float):Body

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

Parameters:

deltaTime

The time to integrate body by. This value may be negative to integrate back in time.

Returns:

A refernce to 'this' Body

inlineisStatic():Bool

Fast equivalent to body.type == BodyType.STATIC

Returns:

True if body is Static.

inlineisDynamic():Bool

Fast equivalent to body.type == BodyType.DYNAMIC

Returns:

True if body is Dynamic.

inlineisKinematic():Bool

Fast equivalent to body.type == BodyType.KINEMATIC

Returns:

True if body is Kinematic.

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:

A copy of this Body.

setVelocityFromTarget(targetPosition: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.

Parameters:

targetPosition

The target position for Body.

targetRotation

The target rotation for Body.

deltaTime

The time step for next call to space.step().

Returns:

A reference to 'this' Body.

Throws:

#

If targetPosition is null or disposed of.

@:value({ output : null, depth : -1 })connectedBodies(depth:Int = -1, ?output:BodyList):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.

Parameters:

depth

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

An optional list to append results to, if left as null then a new list is created.

Returns:

A list of the connected bodies up to the given graph depth.

@:value({ output : null, depth : -1, type : null })interactingBodies(?type:InteractionType, depth:Int = -1, ?output:BodyList):BodyList

Compute set of bodies interacting with this body.

Parameters:

type

When not equal to null, this parameter controls what sort of interaction we permit in the search.

depth

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

An optional list to append results to, if left as null then a new list is created.

Returns:

A list of the interacting bodies up to the given graph depth.

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:

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

Throws:

#

If body is not in a Space.

@:value({ weak : false })localPointToWorld(point:Vec2, weak:Bool = false):Vec2

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

Parameters:

point

The point to transform.

weak

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:

The result of the transformation.

Throws:

#

If point is null or disposed of.

@:value({ weak : false })worldPointToLocal(point:Vec2, weak:Bool = false):Vec2

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

Parameters:

point

The point to transform.

weak

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:

The result of the transformation.

Throws:

#

If point is null or disposed of.

@:value({ weak : false })localVectorToWorld(vector:Vec2, weak:Bool = false):Vec2

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

Parameters:

vector

The vector to transform.

weak

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:

The result of the transformation.

Throws:

#

If vector is null or disposed of.

@:value({ weak : false })worldVectorToLocal(vector:Vec2, weak:Bool = false):Vec2

Transform vector from world coordinates to Body's local coordinates

Parameters:

vector

The vector to transform.

weak

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:

The result of the transformation.

Throws:

#

If vector is null or disposed of.

@:value({ sleepable : false, pos : null })applyImpulse(impulse:Vec2, ?pos:Vec2, 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.

Parameters:

impulse

The impulse to apply given in world coordinates.

pos

The position to apply impulse given in world coordinates. (default body.position)

sleepable

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:

A reference to 'this' Body.

Throws:

#

If impulse is null or disposed of.

#

If pos is non-null and disposed of.

@:value({ sleepable : false })applyAngularImpulse(impulse:Float, sleepable:Bool = false):Body

Apply a pure angular impulse to Body.

Parameters:

impulse

The angular impulse to apply.

sleepable

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:

A reference to 'this' Body.

translateShapes(translation: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.

Parameters:

translation

The local translation to apply to Shapes.

Returns:

A reference to this Body.

Throws:

#

If translation is null or has been disposed of.

#

If this Body is static, and inside of a Space.

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.

Parameters:

angle

The angle to rotate shapes by in clockwise radians.

Returns:

A reference to this Body.

Throws:

#

If this Body is static, and inside of a Space.

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.

Parameters:

scaleX

The x-coordinate factor of scaling.

scaleY

The y-coordinate factor of scaling.

Returns:

A reference to this Body.

Throws:

#

If this Body is static, and inside of a Space.

#

If Body contains Circle shapes, and scaleX != scaleY

transformShapes(matrix: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.

Parameters:

matrix

The transformation matrix to apply to each Shape.

Returns:

A reference to this Body.

Throws:

#

If this Body is static, and inside of a Space.

#

If matrix is null or singular.

#

If Body contains Circle shapes, and input matrix is not equiorthogonal.

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:

A reference to this Body.

rotate(centre: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.

Parameters:

centre

The centre of rotation in world coordinates.

angle

The angle to rotate body by in clockwise radians.

Returns:

A reference to this Body.

Throws:

#

If this Body is static, and inside of a Space.

#

If centre is null or disposed of.

setShapeMaterials(material:Material):Body

Set material of all shapes.

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

Parameters:

material

The material to set Shape's material to.

Returns:

A reference to this Body.

setShapeFilters(filter:InteractionFilter):Body

Set interaction filter of all shapes.

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

Parameters:

filter

The filter to set Shape's filter to.

Returns:

A reference to this Body.

setShapeFluidProperties(fluidProperties:FluidProperties):Body

Set fluidProperties of all shapes.

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

Parameters:

fluidProperties

The fluidProperties to set Shape's fluidProperties to.

Returns:

A reference to this Body.

@:value({ freshOnly : false, body : null })normalImpulse(?body:Body, freshOnly:Bool = false):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.

Parameters:

body

The Body to restrict consideration of impulses with. (default null)

freshOnly

If true, then only 'new' contact points will be considered. (default false)

Returns:

The summed effect of impulses acting on Body.

@:value({ freshOnly : false, body : null })tangentImpulse(?body:Body, freshOnly:Bool = false):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.

Parameters:

body

The Body to restrict consideration of impulses with. (default null)

freshOnly

If true, then only 'new' contact points will be considered. (default false)

Returns:

The summed effect of impulses acting on Body.

@:value({ freshOnly : false, body : null })totalContactsImpulse(?body:Body, freshOnly:Bool = false):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.

Parameters:

body

The Body to restrict consideration of impulses with. (default null)

freshOnly

If true, then only 'new' contact points will be considered. (default false)

Returns:

The summed effect of impulses acting on Body.

@:value({ freshOnly : false, body : null })rollingImpulse(?body:Body, 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.

Parameters:

body

The Body to restrict consideration of impulses with. (default null)

freshOnly

If true, then only 'new' contact points will be considered. (default false)

Returns:

The summed effect of impulses acting on Body.

@:value({ body : null })buoyancyImpulse(?body:Body):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.

Parameters:

body

The Body to restrict consideration of impulses with. (default null)

Returns:

The summed effect of impulses acting on Body.

@:value({ body : null })dragImpulse(?body:Body):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.

Parameters:

body

The Body to restrict consideration of impulses with. (default null)

Returns:

The summed effect of impulses acting on Body.

@:value({ body : null })totalFluidImpulse(?body:Body):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.

Parameters:

body

The Body to restrict consideration of impulses with. (default null)

Returns:

The summed effect of impulses acting on Body.

constraintsImpulse():Vec3

Evaluate sum effect of all constraint impulses on this Body.

Returns:

The summed effect of constraint impulses acting on Body.

@:value({ freshOnly : false, body : null })totalImpulse(?body:Body, freshOnly:Bool = false):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.

Parameters:

body

The Body to restrict consideration of impulses with. (default null)

freshOnly

If true, then only 'new' contact points will be considered when evaluating contact impulses. (default false)

Returns:

The summed effect of impulses acting on Body.

contains(point:Vec2):Bool

Determine if point is contained in Body.

Parameters:

point

The point to test containment for in world coordinates.

Returns:

True if point is contained.

Throws:

#

If point is null or has been disposed.

@:keeptoString():String

@private

Inherited Variables

Defined by Interactor

@:value(null)zpp_inner_i:ZPP_Interactor = null

@private

read onlyid:Int

Unique id of this Interactor.

read onlyuserData:Dynamic<Dynamic>

Dynamic object for user to store additional data.

This object cannot be set, only its dynamically created properties may be set. In AS3 the type of this property is &#42

This object will be lazily constructed so that until accessed for the first time, will be null internally.

read onlycastShape:Null<Shape>

Fast equivalent to cast(interactor, Shape)

read onlycastBody:Null<Body>

Fast equivalent to cast(interactor, Body)

read onlycastCompound:Null<Compound>

Fast equivalent to cast(interactor, Compound)

group:Null<InteractionGroup>

InteractionGroup assigned to this Interactor.

read onlycbTypes:CbTypeList

Set of CbType's assigned to this Interactor.

Inherited Methods

Defined by Interactor

inlineisShape():Bool

Fast equivalent to Std.isOfType(interactor, Shape)

Returns:

true if this Interactor is a Shape.

inlineisBody():Bool

Fast equivalent to Std.isOfType(interactor, Body)

Returns:

true if this Interactor is a Body.

inlineisCompound():Bool

Fast equivalent to Std.isOfType(interactor, Compound)

Returns:

true if this Interactor is a Compound.