Physics v2 constraints

I encountered some issues while writing this demo,

When I load a mesh, I want to add Constraints between two objects. My idea is to constantly set parents to obtain positions and then connect them together,there is an error where the position of the body shape and the position of the mesh are not at the same point
I don’t think my approach is correct, I don’t know how to operate the correct approach

const meshes = wheel.getChildMeshes()
    meshes[0].position = $.Vector3.Zero()
    meshes[1].position = $.Vector3.Zero()

    // set parent inorder to adjust wheel position
    wheel.parent = carBody

    // This is to obtain the positions of the four wheel axles, And then I can hope to install the wheels on it
    const name = meshes[0].name.slice(0, meshes[0].name.length - 1) + '2'
    const pivot = this.scene.getMeshByName(name)
    wheel.position = pivot.position.clone()


How should I set the parameters in the constraint

// set Constraints
    const joint = new $.BallAndSocketConstraint(


Debugging the scene with the viewer, I found that the wheels were misaligned with the right meshes:

This is because you were creating the aggregate with the parent body, which doesn’t have the transform to align the child.

As for the constraint parameters, the pivots need to be in the LOCAL frame of each body, which looks like this in your case:

Also, the ball and socket constraint isn’t the most adequate for this situation, as it still allows the wheels to rotate freely along the axis:

Here’s an updated playground: Constraints wheel & pivot | Babylon.js Playground (

It’s based on a Playground that I did a while ago: Physics Car | Babylon.js Playground (

Thanks a lot . Your help has been very useful to me, and I need to study this knowledge thoroughly

Are there any relevant helpful documents for constraints (Physics6DoFConstraint)? There is still a little bit of knowledge available for reference.

We have the constraints documentation: Constraints | Babylon.js Documentation (

Hi, master
axisA: new BABYLON.Vector3(1, 0, 0),
axisB: new BABYLON.Vector3(1, 0, 0),
perpAxisA: new BABYLON.Vector3(0,1,0),
perpAxisB: new BABYLON.Vector3(0,1,0)

In Physics6DoFConstraint, do you only need to set two of these four parameters?
If 4 are set at the same time, axisA and perpAxisA will occasionally twitch.
Literally understood from the document, the parameter axisA is to determine and set LINEAR_X/ANGULAR_X. Therefore, perpAxisA has also been implemented. If you set perpAxisA again and do not keep it unified with axisA, it will twitch.

An axis in the space of the first body which determines how
distances/angles are measured for LINEAR_X/ANGULAR_X limits.

Is there any problem with my understanding? Can you please give me some advice?

I tried it several times and found that axisA and perpAxisA must be set at the same time to determine the coordinate axis.

Can you describe more exactly what you mean by “twitch” here? If possible, with a PG?

If the perpAxis isn’t provided, it will be automatically calculated:

If the axisA is provided as (1,0,0), the getNormalToRef function results in (0,-1,0), which might not be what you expect: Babylon.js Playground ( If you want to control the axis precisely, it’s preferrable to provide all of them.

1 Like

I think I have found the problem. I suspect it is caused by improper settings of axisA and perpAxisA.

hello master,
How to make the wheel rotate automatically? I want to make the wheel rotate with angular speed through physical.

I think such a racing game can be born

applyImpulse cannot guarantee that the car will keep moving forward. Perhaps only by adding power to the wheels can the car move forward.

Hi! There’s currently a bug with the physics system, where you need to apply a small impulse to the wheels to make the setAxisMotorTarget work. With that, the car can start and stop :slight_smile: I updated the demo with that, and turning the wheels too (thanks @eoin for answering my questions!) Physics Car | Babylon.js Playground (

1 Like

Oh!!!, this is perfect, you can even turn the steering wheel

1 Like