> Learn all about physics pivots and axes in Babylon.js.

Source: https://doc.babylonjs.com/legacy/physics/pivotsAxes

# Pivots and Axes

Through the use of Playgrounds, this section considers how the pivot and axis parameters of the hinge joint affect the behavior of the joint in the three physics engines.

1. Cannon.js;
2. Oimo.js;
3. Ammo.js

See [How to Use The Physics' Engines](https://doc.babylonjs.com/legacy/physics/usingPhysicsEngine) for an overall view of setting up and using the three plugins.

In the examples on this page, a hinge joint and a main body are added to a connected axle using

```javascript
connectedAxle.physicsImpostor.addJoint(mainBody.physicsImpostor, joint);
```
The following parameters need to be set:

* mainPivot: main body pivot;
* mainAxis: main body axis ;
* connectedPivot: connected axle pivot;
* connectedAxis: connected axle axis.

In all the following Playgrounds, the X axis is red, the Y axis is green, and the Z axis is blue. Unless clearly stated otherwise, gravity is zero. 

The main body is a purple box and the connected axle is a yellow box. Local axes are shown for both.

The purple sphere marks the position of the main pivot and is the center of rotation for the main body around the local axis of the main body. The yellow sphere marks the position of the connected pivot, which is the negative of the set value for the connected pivot. 

The initial position of the main body is set by the values of the main pivot and the connected pivot and may be shown by the slightly larger black sphere. The radius of rotation for the main body around the main pivot is determined by the value of the connected pivot.

The main body is orientated so that the connected axis and the main axis align but can be in the opposite directions.

When the position and orientation of the bodies' impostors, as set by their pivots, do not match the position of the bodies' meshes, movement can occur at the start as the meshes reposition to match the pivots. 

**Note** In some instances, pivots and axes in `Cannon.js` can result in an axis or body movement that is opposite to that of `Oimo.js` and `Ammo.js`.

The first and second sets of Playgrounds show examples in which the mass of the connected axle is zero. In the first set, the connected axle is positioned at the origin with no rotation. In the second, one or both of the connected axle's position or rotation can be non-zero. In the third set of examples, both the body and the axle have a non-zero mass.

## Playground Examples  - Connected Axle Has Zero Mass and is at the Origin with No Rotation

(A) Parameter Settings
```javascript
mainPivot: new BABYLON.Vector3(0, 0, 0),  
connectedPivot: new BABYLON.Vector3(0, 0, 0), 
mainAxis: new BABYLON.Vector3(0, 1, 0), //
connectedAxis: new BABYLON.Vector3(0, 1, 0)
```

- [Playground: Pivots and Axes (A Parameters)](https://playground.babylonjs.com/#8RQJ1R#2) - Simple example of pivots and axes with A parameters.

----

(B) Parameter Settings
```javascript
mainPivot: new BABYLON.Vector3(0, 5, 0), //set main body position
connectedPivot: new BABYLON.Vector3(0, 0, 0),
mainAxis: new BABYLON.Vector3(0, 1, 0),
connectedAxis: new BABYLON.Vector3(0, 1, 0)
```
- [Playground: Pivots and Axes (B Parameters)](https://playground.babylonjs.com/#8RQJ1R#3) - Simple example of pivots and axes with B parameters.

----

(C) Parameter Settings
```javascript
mainPivot: new BABYLON.Vector3(0, 0, 0),
connectedPivot: new BABYLON.Vector3(5, 0, 0), //adjust main body position and radius of rotation
mainAxis: new BABYLON.Vector3(0, 1, 0),
connectedAxis: new BABYLON.Vector3(0, 1, 0)
```

* [Playground: Pivots and Axes (C Parameters)](https://playground.babylonjs.com/#8RQJ1R#4) - Simple example of pivots and axes with C parameters.

----

(D) Parameter Settings
```javascript
mainPivot: new BABYLON.Vector3(10, 0, 0),
connectedPivot: new BABYLON.Vector3(0, 5, 0),
mainAxis: new BABYLON.Vector3(1, 0, 0), //different axes will orientate main body to align axes.
connectedAxis: new BABYLON.Vector3(0, 1, 0)
```
- [Playground: Pivots and Axes (D Parameters)](https://playground.babylonjs.com/#8RQJ1R#5) - Simple example of pivots and axes with D parameters.

----

(E) Parameter Settings
```javascript
mainPivot: new BABYLON.Vector3(0, 0, 0), //set main body position
connectedPivot: new BABYLON.Vector3(0, 0, 0), //adjust main body position and radius of rotation
mainAxis: new BABYLON.Vector3(0, 0, 1), //different axes will orientate main body to align axes.
connectedAxis: new BABYLON.Vector3(1, 0, 0)
```
- [Playground: Pivots and Axes (E Parameters)](https://playground.babylonjs.com/#8RQJ1R#6) - Simple example of pivots and axes with E parameters.

## Playground Examples  - Connected Axle Has Zero Mass and Position or Rotation Is Non-Zero

Any [translation](https://doc.babylonjs.com/typedoc/classes/babylon.transformnode#translate) or rotation of the connected axle results in the same transformation being applied to the whole hinge joint system.

(F) Parameter Settings
```javascript
mainPivot: new BABYLON.Vector3(0, 0, 0),  
connectedPivot: new BABYLON.Vector3(0, 0, 0), 
mainAxis: new BABYLON.Vector3(0, 1, 0), //
connectedAxis: new BABYLON.Vector3(0, 1, 0)
```

* [Playground: Pivots and Axes (F Parameters)](https://playground.babylonjs.com/#8RQJ1R#7) - Simple example of pivots and axes with F parameters.

----

(G) Parameter Settings
```javascript
mainPivot: new BABYLON.Vector3(0, 0, 0),
connectedPivot: new BABYLON.Vector3(0, 0, 0),
mainAxis: new BABYLON.Vector3(0, 1, 0),
connectedAxis: new BABYLON.Vector3(0, 1, 0)
```
- [Playground: Pivots and Axes (G Parameters)](https://playground.babylonjs.com/#8RQJ1R#8) - Simple example of pivots and axes with G parameters.

----

(H) Parameter Settings
```javascript
mainPivot: new BABYLON.Vector3(5, 0, 0),
connectedPivot: new BABYLON.Vector3(0, 0, 0), 
mainAxis: new BABYLON.Vector3(0, 1, 0),
connectedAxis: new BABYLON.Vector3(0, 1, 0)
``` 
- [Playground: Pivots and Axes (H Parameters)](https://playground.babylonjs.com/#8RQJ1R#9) - Simple example of pivots and axes with H parameters.

----

(J) Parameter Settings
```javascript
mainPivot: new BABYLON.Vector3(10, 0, 0),
connectedPivot: new BABYLON.Vector3(0, 5, 0), //adjust main body position and radius of rotation
mainAxis: new BABYLON.Vector3(0, 1, 0), 
connectedAxis: new BABYLON.Vector3(0, 1, 0)
```
- [Playground: Pivots and Axes (J Parameters)](https://playground.babylonjs.com/#8RQJ1R#10) - Simple example of pivots and axes with J parameters.

----

(K) Parameter Settings
```javascript
mainPivot: new BABYLON.Vector3(10, 0, 0), //set main body position
connectedPivot: new BABYLON.Vector3(0, 5, 0), //adjust main body position and radius of rotation
mainAxis: new BABYLON.Vector3(0, 0, 1), //different axes will rotate main body so stated axes align.
connectedAxis: new BABYLON.Vector3(1, 0, 0)
```
- [Playground: Pivots and Axes (K Parameters)](https://playground.babylonjs.com/#8RQJ1R#11) - Simple example of pivots and axes with K parameters.

## Playground Examples  - Connected Axle Has Non-Zero Mass and is at the Origin with No Rotation

When the position of the main body mesh is not the same as the position imposed on the impostors by the pivots or axes, physics will move the body from its mesh position to the position determined by the pivots and axes. This movement acts in the physics world and will set the hinge joint system in motion. 

In the following example the parameter setting will be applied in four situations, the last two just for fun.

  i. No Motor - main body mesh position and rotation made to be equal to that determined by pivots and axes;  
 ii. No Motor - main body mesh position and rotation different to that determined by pivots and axes;  
iii. Motor Applied - as ii.;  
 iv. Motor Applied in Non-Zero gravity - as ii.

(L) Parameter Settings
```javascript
mainPivot: new BABYLON.Vector3(0, 0, 0),  
connectedPivot: new BABYLON.Vector3(0, 0, 0), 
mainAxis: new BABYLON.Vector3(0, 1, 0),
connectedAxis: new BABYLON.Vector3(0, 1, 0)
```

- [Playground: Pivots and Axes (L(i) Parameters)](https://playground.babylonjs.com/#8RQJ1R#13) - Simple example of pivots and axes with L(i) parameters.
- [Playground: Pivots and Axes (L(ii) Parameters)](https://playground.babylonjs.com/#8RQJ1R#14) - Simple example of pivots and axes with L(ii) parameters.
- [Playground: Pivots and Axes (L(iii) Parameters)](https://playground.babylonjs.com/#8RQJ1R#15) - Simple example of pivots and axes with L(iii) parameters.
- [Playground: Pivots and Axes (L(iv) Parameters)](https://playground.babylonjs.com/#8RQJ1R#16) - Simple example of pivots and axes with L(iv) parameters.

## Further reading

- [How To Use The Physics Engines](https://doc.babylonjs.com/legacy/physics/usingPhysicsEngine)
- [How to use Forces](https://doc.babylonjs.com/legacy/physics/forces)
- [How To Use Joints](https://doc.babylonjs.com/legacy/physics/joints)
- [How To Create Compound Bodies](https://doc.babylonjs.com/legacy/physics/compoundBodies)
- [How To Create Soft Bodies](https://doc.babylonjs.com/legacy/physics/softBodies)
- [How To Use Advanced Features](https://doc.babylonjs.com/legacy/physics/advancedPhysicsFeatures)
