How do you lock multiple bodies in a fixed orientation after translating and rotating them?


I’m trying to get a few bodies to remain in a fixed orientation after i move and rotate them, but it seems that using the LockJoint rotates them out of the desired orientation. Here is a simple example that shows roughly the problem I’m having:

What i’d like to be able to do is take a bunch of bodies, move and rotate them arbitrarily, and then once they are positioned correctly, i want to lock them in place. Anyone know the best way to accomplish this?

Many thanks for any pointers!


Adding @trevordev for the physics part

Also could you detail a bit more the use case ? I am having trouble to understand fully what you are trying to achieve


I’m not sure locking is best for this scenario, instead I would try to create compound physics bodies. Does this playground do what you are trying to accomplish?

See the authoring section of this doc:


Thanks for the replies so far folks!

The example i provided is just a toy, what i am ultimately aiming to do is use the physics engine to do a low-fi simulation of a simple RC aircraft where i’ll be needing to specify the forces acting on a number of bodies. Bodies will represent things like motors, wings/control surfaces, ballast masses etc, and I want to attach the bodies in fixed positions to simulate the rigid body kinematics of the craft. I’ll need to specify the mass of each sub-body, as well as forces on each sub-body calculated from the sub-body’s velocity, orientation, etc. Collisions are not really relevant actually, but it will be convenient to have direct access to all of the methods of each individual sub-body when making these calculations.

I initially experimented with setting the various objects to all have one parent, but when you do that, forces seem to be applied in the parent frame (or maybe the world frame, i haven’t investigate this full, but in anycase, it’s not in the body’s local frame). Conceptually, it is much simpler if i can apply forces in the individual body frames of each sub-body.

And indeed, i have this working exactly as intended… until i try to rotate the bodies. If i use a LockJoint to fix the sub-bodies in relative positions, everything works just right and the simulation performs as intended when i apply the desired forces to the various bodies… but when i try to rotate the bodies before applying the LockJoint, i get weird behavior.

I’m sure there are a number of ways to accomplish this, but for the sake of argument: if i want to use LockJoints to fix the position and orientation of a set of bodies, how might that be done? Is it possible?

(FWIW, i’ve read the docs, googled, and perused the source on github extensively and I’m quite stuck… but not for lack of effort :slight_smile: )

Thank you! :slight_smile:


Looking into this more: it seems like it may be an upstream bug in Cannon.js –

Now that i’m digging into this a bit more, I see that Cannon is not really being maintained and hasn’t been for several years, so i may try to switch to the new Ammo backend since Ammo is still actively developed and the plugin also appears to be getting active attention. Unfortunately, this will mean a rewrite, but what can you do :-/

Thanks all for your help! :slight_smile:


No problem, I should eventually make the cannon work consistently with the ammo example I shared, I think there might be a way to get cannon working without the joint constraint and instead use composite shape but the babylon cannon plugin doesn’t yet support empty parent node method I had to use to get ammo working as expected but there’s currently a couple other issues I’m tackling at the moment.