Joints
A joint in a physics engine is a constraining feature between two bodies. This area has the largest differences between the physics engine both in the joints available and the names used. Not all native joints are available in some plugins.
Playgrounds are available to check out the coding. In the playgrounds the physics' engine used can be changed by selecting which ones to comment out.
See How to Use The Physics' Engines for an overall view of setting up and using the three plugins.
Physical Joint Types
Number | Joint | Name | Notes |
---|---|---|---|
Number 1 | Joint ![]() | Name Hinge | Notes Single Axis Rotation |
Number 2 | Joint ![]() | Name Ball and Socket | Notes Multi Axis Rotation |
Number 3 | Joint ![]() | Name Cone Twist | Notes Unrestricted rotation (Twist) on One Axis, Limited Rotation (in Cone) On Others |
Number 4 | Joint ![]() | Name Wheel | Notes Two Axes Rotation |
Number 5 | Joint ![]() | Name Slider | Notes Single Axis Translation and Rotation |
Number 6 | Joint ![]() | Name Prismatic | Notes Single Axis Translation Only |
Number 7 | Joint ![]() | Name Distance | Notes Set Bodies a Fixed Distance Apart |
Number 8 | Joint ![]() | Name Locked | Notes Bodies Act As One Body |
Babylon.js Joints
The following table lists those joints within Babylon.js and where available their equivalence to each other and their link to the native joints
Babylon.js Joint | Cannon Joint | Oimo Joint | Ammo Joint | Helper Class |
---|---|---|---|---|
Babylon.js Joint HingeJoint | Cannon Joint HingeConstraint | Oimo Joint HingJoint | Ammo Joint HingeConstraint | Helper Class Yes |
Babylon.js Joint BallAndSocketJoint | Cannon Joint PointToPointConstraint | Oimo Joint BallAndSocketJoint | Ammo Joint Point2PointConstraint | Helper Class no |
Babylon.js Joint WheelJoint | Cannon Joint ---- | Oimo Joint WheelJoint | Ammo Joint Point2PointConstraint | Helper Class Hinge2Joint Only |
Babylon.js Joint SliderJoint | Cannon Joint ---- | Oimo Joint SliderJoint | Ammo Joint SliderConstraint | Helper Class No |
Babylon.js Joint PrismaticJoint | Cannon Joint ---- | Oimo Joint PrismaticJoint | Ammo Joint ---- | Helper Class No |
Babylon.js Joint DistanceJoint | Cannon Joint DistanceConstraint | Oimo Joint DistanceJoint | Ammo Joint Point2PointConstraint with Added Constraints | Helper Class Yes |
Babylon.js Joint LockJoint | Cannon Joint LockConstraint | Oimo Joint ---- | Ammo Joint FixedConstraint | Helper Class No |
Babylon.js Joint SpringJoint | Cannon Joint Spring | Oimo Joint ---- | Ammo Joint ---- | Helper Class No |
The method to form a joint and connect one body (main) to a second body (connected) is
var joint = new BABYLON.PhysicsJoint( BABYLON.PhysicsJoint.TYPE_OF_JOINT, jointData);
mainImpostor.addJoint(connectedImpostor, joint);
where the jointData
object contains the properties for the joint.
Hinge Joint
For a hinge the only component of any force that produces movement is one perpendicular to the axis of the hinge. It is possible however that a large impulse in another direction can produce a reaction between the two bodies that does produce an impulse component in the perpendicular direction.
The jointData
object for a hinge contains the following properties
- mainAxis: Vector3; the axis for the main body.
- connectedAxis: Vector3; the axis for the connected body, usually the same as the main axis.
- mainPivot: Vector3; the pivot point for the main body.
- connectedPivot: vector3; the pivot point for the connected body, the negative of the connected body's position.
A hinge joint can also be created with a helper class
var joint1 = new BABYLON.HingeJoint(jointData);
PhysicsJoint Playground
Helper Class Playground
Since a hinge gives movement about only one axis it would seem to make sense to replace the representation of the hinge with a cylinder. Doing this, reshaping the box and keeping the sphere mesh imposter as a sphere does produce changes.
In this case, for all the physics' engines whatever the direction of impulse set it is applied in a direction perpendicular to the hinge axis.
PhysicsJoint Playground
Helper Class Playground
You can, of course, use a cylinder impostor for the cylinder mesh
PhysicsJoint Playground
Helper Class Playground
Ball And Socket Joint
For a ball and socket joint a force can produce rotation about all three axes.
The positioning of the connected body is determined by the connected pivot. The jointData
object for a ball and socket contains the following properties
- mainPivot: Vector3; the pivot point for the main body.
- connectedPivot: vector3; the pivot point for the connected body, the negative of the connected body's position.
PhysicsJoint Playground
Wheel Joint
For a wheel the a force produces rotation about two axes.
The jointData
object for a hinge contains the following properties
- mainAxis: Vector3; the first axis.
- connectedAxis: Vector3; the second axis.
- mainPivot: Vector3; the pivot point for the main body.
- connectedPivot: vector3; the pivot point for the connected body, the negative of the connected body's position.
Note In the Oimo.js
playgrounds changing the contact point of the force will not produce a spin around the axis perpendicular to the sphere's surface.
PhysicsJoint Playground
The PhysicsJoint
called Hinge2Joint
can be used as an alternative. Note however that there is no helper call WheelJoint
and the helper must be
var joint1 = new BABYLON.Hinge2Joint(jointData);
When this helper class is used with Ammo.js
it forms a BallAndSocketJoint
not a WheelJoint
. So a change of contact point can produce a spin around the axis perpendicular to the sphere's surface when using Ammo.js
.
Helper Class Playgrounds
Slider Joint
Currently Oimo.js
only. Any component of force in the direction of the slider axis will move the body along this axis. Any component of force perpendicular to the slider axis will rotate the body around the axis.
The jointData
object for a slider contains the following properties
- mainAxis:Vector3, slider and rotational axis
- collision: Boolean, true if the main and connected bodies react at collision.
PhysicsJoint Playgrounds
Prismatic Joint
Currently Oimo.js
only. Only the component of force in the direction of the axis will move the body and the movement will be a translation only along this axis.
The jointData
object for a slider contains the following properties
- mainAxis:Vector3, prismatic axis
- collision: Boolean, true if the main and connected bodies react at collision.
PhysicsJoint Playgrounds
Distance Joint
The jointData
object for a distance joint contains the following properties
- maxDistance: number.
PhysicsJoint Playgrounds
Helper Class Playgrounds
LockJoint
Cannon.js
only. The two connected bodies act as one body.
PhysicsJoint Playgrounds
Spring
Cannon,js
Only. The jointData
object for a spring contains the following properties
- length: number.
- stiffness: number.
- damping: number.
PhysicsJoint Playgrounds
Motors
A motor requires a target speed (angular velocity) and the maximum force (torque) that can be applied by the motor. It is possible to set a torque that is insufficient for it to reach the target speed. Depending on the shape and mass of the body the torque has to overcome the moment of inertia of the body. A too low value for the torque will make the body struggle and stutter to reach the target speed. Even attempting to simulate a virtual motor in zero gravity with no friction and a zero mass for the axel joint turning a cylinder can make determining an appropriate value for the torque difficult. Since moment of inertia, which determines torque, also depends on the volume of the body it is a good idea to keep linear dimensions around 10 or less though it is probably worth experimenting to get obtain what you need. Adding gravity, friction and further bodies, that the motored body has to move, makes it even more difficult. Sometimes in your project all you will want is for the motor to turn. This can be achieved by just setting the target speed (the motor will be over torqued by default), as in
joint.setMotor(speed);
At other times it will be important to set a value for the torque that limits the motor operation, you can do this with
joint.setMotor(speed, force);
The table below shows the joints that a motor can be added to.
Babylon.js Joint | Cannon Motor | Oimo Motor | Ammo Motor |
---|---|---|---|
Babylon.js Joint BABYLON.PhysicsJoint.HingeJoint | Cannon Motor Yes | Oimo Motor Yes | Ammo Motor Yes |
Babylon.js Joint BABYLON.PhysicsJoint.WheelJoint | Cannon Motor No | Oimo Motor Yes | Ammo Motor No |
Babylon.js Joint BABYLON.PhysicsJoint.Hinge2Joint | Cannon Motor No | Oimo Motor Yes | Ammo Motor No |
Babylon.js Joint BABYLON.PhysicsJoint.SliderJoint | Cannon Motor No | Oimo Motor Yes | Ammo Motor No |
To add a motor to one of these joints simply replace PhysicsJoint
with MotorEnabledJoint
and set the motor on the joint.
var joint = new BABYLON.PhysicsJoint( BABYLON.PhysicsJoint.TYPE_OF_JOINT, jointData);
mainImpostor.addJoint(connectedImpostor, joint);
becomes
var joint = new BABYLON.MotorEnabledJoint(BABYLON.PhysicsJoint.TYPE_OF_JOINT, jointData);
mainImpostor.addJoint(connectedImpostor, joint);
joint.setMotor(target speed, maximum torque)
The helper classes for HingeJoint
and Hinge2Joint
are already motorised and only setMotor
is needed.
Playground Examples
Hinge Motor Speed Only
MotorEnabledJoint Playground
Helper Class Playground
Hinge Motor Speed and Torque (Force)
Different engines use differing scales for the torque and a little trial and error is often necessary to determine the required effect.
- For Cannon.js try starting with torque values between 1/100 to 1/10 of the total mass value;
- For Ammo.js try starting with torque values between 1/100 and 1/10 of total mass value;
- For Oimo.js try starting with torque values about 1 to 10 times the total mass value.
In the hinge motor playgrounds below there are two wheels you can try out different torque values for each wheel to see how they vary. Note that they are in zero gravity, with zero friction and the axel has zero mass. In other situations torque values may need a larger factor than those given above.
MotorEnabledJoint Playground
Helper Class Playground
Wheel (Hinge2) Motor
MotorEnabledJoint Playgrounds
Slider Motor
The motor rotates the body around the slider axis.
MotorEnabledJoint Playground
Further reading
Using A Physics Engine
Learn how to use one of the available physics engines in Babylon.js.

Forces
Learn all about applying physical forces in Babylon.js.

Pivots and Axes
Learn all about physics pivots and axes in Babylon.js.

Compound Bodies
Learn all about physics compound bodies in Babylon.js.

Soft Bodies
Learn all about physics soft bodies in Babylon.js.

Advanced Physics Features
Unlock the full potential of physics with advanced physics features in Babylon.js.
