The physics class on an object is used to control it's interaction with the physics engine.
Properties
enable |
A boolean value set to true to switch on the physics engine for this object. |
mass |
A floating point property representing the mass of the object. |
friction |
A floating point property representing the friction on the object, where 0 is no friction. |
useRotation |
A boolean property which when set to false will stop the physics engine from passing rotations to the object. |
gravity |
A boolean value that when true means scene gravity is acting on the object. |
restitution |
A floating point value representing the restitution of the object (bounce) between 0 and 1 (requires other objects to also have restitution set). |
active |
Defaults to true, but if set to false, the object will be assumed to be in a state of rest. This can be useful when setting up a stack of objects. |
immovable |
If true the object will not move in the physics system. |
margin |
A floating point value that determines the size of the border around the actual shape to use to help prevent errors. |
massOffset |
A Vector determining difference between the centre of mass and the 0,0,0 origin of the object (defaults to 0,0,0). |
type |
A string value, set this before enabling physics to change the basic physics class of object. Current values are 'normal', 'cloth' or 'character'. |
Methods
applyCentralForce(forceVector) |
Applies a constact force to the object through the centre. |
applyCentralImpulse(impulseVector) |
Applies a one off impulse to the object through the centre. |
applyImpulse(impulseVector, posVector) |
Applies the given Vector as a constant torque about the X/Y/Z axes. |
applyTorque(torqueVector) |
Applies the given Vector as a constant torque about the X/Y/Z axes. |
applyTorqueImpulse(impulseVector) |
Applies the given Vector as an impulse torque about the X/Y/Z axes. |
setConstraintBox(vPosMin,vPosMax,vAngMin,vAngMax) |
Applies a constraint to the object to stay within a box with Vectors vPosMin and vPosMax defining the size. vAngMin and vAngMax determine the freedom in X/Y/Z axes. Use -UtilMath.infinity and +UtilMath.infinity to declare an axis as completely free. |
setDamping(posFactor, angFactor) |
Sets the damping of linear movement to the floating point value posFactor, and the damping of angular movement to the floating point value angFactor. |
setConstraintPoint(pivotPos, pivotOffset) |
Applies a constraint to the object to stay fixed to a point, where pivotPos is the Vector point in the world to be fixed to, and pivotOffset is the Vector offset from the centre of the object where the pivot attaches. |
setConstraintHinge(pivotPos, pivotAxis, pivotOffset) |
Applies a constraint to the object to stay fixed to a hinge from a point along a given axis, where pivotPos is the Vector point in the world to be fixed to, pivotAxis is a Vector direction of the hinge and pivotOffset is the Vector offset from the centre of the object where the pivot attaches. |
setConstraintNone() |
Removes any constraints that have been applied to this object. |
Examples
function onInit()
{
object.physics.enable=true;
object.physics.mass=2.0;
object.physics.friction=0.0;
object.applyCentralImpulse(new Vector(10,0,0));
}
Remarks
Try not to switch objects in and out of the physics engine too often as there will be a performance penalty to pay.
See Also


