class nape.phys.Body extends Interactor
Available on all platforms
Class representing a physics Rigid Body.
Instance Fields
var 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
var 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
var angularVel:Float
Angular velocity of Body in clockwise rad/s
*
* A static body cannot have its angular velocity set.
*
* @default 0
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.
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
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.
var 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.
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.
var constraints:ConstraintList
Set of constraints using this Body.
*
* This list contains those constraints that are inside of a Space only.
*
* This list is immutable.
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
var 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
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)
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.
Method of computing mass as seen by gravity.
*
* This value will be implicitly set by modifying gravMass or gravMassScale properties.
*
* @default GravMassMode.DEFAULT
var 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.
Moment of inertia of this Body.
*
* Setting this value will implicitly change the inertiaMode to FIXED.
Method of computing Body moment of inertia.
*
* This value will be set implicitly by modifying Body inertia property.
*
* @default InertiaMode.DEFAULT
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
var 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.
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
var 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.
*
* @default (0,0)
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.
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
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
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)
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
List of shapes owned by Body.
*
* Appending a Shape to this list is equivalent to shape.body = this
*
* @default []
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.
var 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).
*
* @default (0,0)
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
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)
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.
function new(?type:BodyType = null, ?position:Vec2 = null):Void
Construct a new Body.
*
*
type | The type of Body to create. (default DYNAMIC) * |
position | The initial position for object. (default (0,0)) * |
returns | The newly constructed 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. |
function applyAngularImpulse(impulse:Float, ?sleepable:Bool = false):Body
Apply a pure angular impulse to Body. * *
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. |
function applyImpulse(impulse:Vec2, ?pos: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.
*
*
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. |
function buoyancyImpulse(?body:Body = null):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.
*
*
body | The Body to restrict consideration of impulses with. * (default null) * |
returns | The summed effect of impulses acting on Body. |
function 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.
*
*
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. |
function constraintsImpulse():Vec3
Evaluate sum effect of all constraint impulses on this Body. * *
returns | The summed effect of constraint impulses acting on Body. |
function contains(point:Vec2):Bool
Determine if point is contained in Body. * *
point | The point to test containment for in world coordinates. * |
returns | True if point is contained. * |
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. |
function 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. |
function dragImpulse(?body:Body = null):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.
*
*
body | The Body to restrict consideration of impulses with. * (default null) * |
returns | The summed effect of impulses acting on Body. |
function integrate(deltaTime:Float):Body
Integrate body forward in time, taking only velocities into account. * *
deltaTime | The time to integrate body by. This value may be negative to * integrate back in time. * |
returns | A refernce to 'this' Body |
function interactingBodies(?type:InteractionType = null, ?depth:Int = -1, ?output:BodyList = null):BodyList
Compute set of bodies interacting with this body. * *
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. |
function isKinematic():Bool
Fast equivalent to body.type == BodyType.KINEMATIC
*
returns | True if body is Kinematic. |
function localPointToWorld(point:Vec2, ?weak:Bool = false):Vec2
Transform a point from Body's local coordinates to world coordinates. * *
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. * |
function localVectorToWorld(vector:Vec2, ?weak:Bool = false):Vec2
Transform vector from Body's local coordinates into world coordinates.
*
*
*
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. * |
function normalImpulse(?body:Body = null, ?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.
*
*
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. |
function 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.
*
*
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. |
function 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.
*
*
centre | The centre of rotation in world coordinates. * |
angle | The angle to rotate body by in clockwise radians. * |
returns | A reference to this Body. * |
function 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.
*
*
angle | The angle to rotate shapes by in clockwise radians. * |
returns | A reference to this Body. * |
function 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.
*
*
scaleX | The x-coordinate factor of scaling. * |
scaleY | The y-coordinate factor of scaling. * |
returns | A reference to this Body. * |
function setShapeFilters(filter:InteractionFilter):Body
Set interaction filter of all shapes.
*
* Equivalent to: body.shapes.foreach(function (shape) shape.filter = filter)
*
*
filter | The filter to set Shape's filter to. * |
returns | A reference to this Body. |
function setShapeFluidProperties(fluidProperties:FluidProperties):Body
Set fluidProperties of all shapes.
*
* Equivalent to: body.shapes.foreach(function (shape) shape.fluidProperties = fluidProperties)
*
*
fluidProperties | The fluidProperties to set Shape's fluidProperties to. * |
returns | A reference to this Body. |
function setShapeMaterials(material:Material):Body
Set material of all shapes.
*
* Equivalent to: body.shapes.foreach(function (shape) shape.material = material)
*
*
material | The material to set Shape's material to. * |
returns | A reference to this Body. |
function 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.
*
*
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. |
function tangentImpulse(?body:Body = null, ?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.
*
*
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. |
function totalContactsImpulse(?body:Body = null, ?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.
*
*
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. |
function totalFluidImpulse(?body:Body = null):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.
*
*
body | The Body to restrict consideration of impulses with. * (default null) * |
returns | The summed effect of impulses acting on Body. |
function totalImpulse(?body:Body = null, ?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.
*
*
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. |
function 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.
*
*
matrix | The transformation matrix to apply to each Shape. * |
returns | A reference to this Body. * |
function 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.
*
*
translation | The local translation to apply to Shapes. * |
returns | A reference to this Body. * |
function worldPointToLocal(point:Vec2, ?weak:Bool = false):Vec2
Transform a point from world coordinates to Body's local coordinates. * *
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. * |
function worldVectorToLocal(vector:Vec2, ?weak:Bool = false):Vec2
Transform vector from world coordinates to Body's local coordinates
*
*
*
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. * |