Are motorized constraints still being introduced?

Motor is introduced in Phicisc v1(Cannon, Ammo, Oimo), but not in Phicisc v2(havok).
I want this very much.

Or maybe the function is there, but I don’t think this function is described in the documentation.

v1
https://doc.babylonjs.com/legacy/physics/joints#motors
v2
https://doc.babylonjs.com/features/featuresDeepDive/physics/constraints

This requires us to use techniques when moving things around in physical space. For example, rotation.

Will setMotor ever be introduced? Or is it in place but not documented?

If possible, I feel that a get~~ function to measure relative rotations and distances would be a great help to those trying to work with physics in Babylon.js.

1 Like

Hi!

Maybe this topic will help you:

1 Like

@roland

Thanks for the information, I was looking at that article too.

It seems that the person who asked the question in that article got the answer, but honestly I couldn’t understand what kind of solution he got.
The fundamental problem is that things that were in v1 are no longer in v2, so I would be most grateful if you could provide that.

Alternatively, I would like to see more documentation on the use of Motor with 6DF constraints.

As a beginner, I don’t want other beginners who are interested in babylon physics to suffer the same way.

Let’s ask @fabienrohrer to help you! :slight_smile:
Could you please?

1 Like

Hej,

I can gladly help you with this topic. My project uses physics v2 (Havok) and motors. (At some point, I migrated it from v1 to v2, and I tried every physics engine).

First of all, I recommend you A LOT to use the physics engine v2. It is much more reliable and performant. Every other physics engine have disastrous bugs (center of mass computation, missing primitives or constraints, issues in compound objets, etc.). I can’t imagine to use them in a serious project. Moreover the v2 API is much more logical and close to a modern physics engine.

Motors are indeed the black spot of v2. Constraints are quite easy to setup like in this example: Babylon.js Playground
… but when it’s about to motorize them, it becomes a nightmare.

The first observation to do is that every constraint is finally initialized as an Havok 6DOF constraint: Babylon.js/packages/dev/core/src/Physics/v2/Plugins/havokPlugin.ts at master · BabylonJS/Babylon.js · GitHub

To have a maximum power of expression, I finally coded all the constraints (hinge, prismatic, ball and socket, and lock) of my project directly as Physics6DoFConstraint constraints. To do so please refer to the example above. The tricky part is that every PhysicsConstraintParameters if the Physics6DoFConstraint constructor should be correctly setup. And don’t underestimate the perpAxis :slight_smile:

… and I finally use the Physics6DoFConstraint.setAxisMotor* API to motorize them.

Here is a working sample:

To be honest, computing the 6DOF parameters has been a nightmare. In particular in my project were all the objects are shifted and rotated. But I finally get them work, even a motorized prismatic joint.

Good luck with this!
Cheers.

3 Likes

Thanks a lot! :heart_eyes_cat:

1 Like

@roland san Thank you.

@fabienrohrer Thank you for responding to our request.

I understood that the correct path was to master Physics6DoFConstraint.
I would like to change my understanding of perpAxis.

By showing me your sample and rewriting it a little, I was able to understand it better.
Thank you again.

Let me ask you one additional question.
As I wrote at the end of the first question, how do you get the current angle when using Motor?

1 Like

As I wrote at the end of the first question, how do you get the current angle when using Motor?

This is a very problematic point. If you look at the Havok API, it seems this property is not accessible:
@babylonjs/havok - npm => click on HavokPhysics.d.ts

Finally, as the Havok body and the Babylon mesh position and orientation are accessible, implementing a function that computes the expected angle or the expected distance is possible in theory, but I never found a perfect way to do so. There are always issues with bounds and weird cases.

I have for example this function:

  // ! works only from -Math.Pi / 2 to Math.Pi / 2 :-(
  angleWithAnchor() { // TODO: improve angle with anchor to support a bigger range, and several axes.
    const m0 = this.node;
    const m1 = this.anchors[0];

    const wm0 = m0.getWorldMatrix().getRotationMatrix();
    const wm1 = m1.getWorldMatrix().getRotationMatrix();
    const rm = wm0.multiply(wm1.transpose());
    const q = new Quaternion();
    rm.decompose(undefined, q, undefined);
    const ea = q.toEulerAngles();
    // console.log(ea);
    const angle = ea.x;
    // const angle = ea.x + ea.y + ea.z;
    return angle;
  }
  • you have to fix m0 and m1
  • there are limits were this is not working
  • this only works for hinges along the X axis

If somebody finds a better way, I would be happy to get it too :stuck_out_tongue:

2 Likes

@fabienrohrer san.

If somebody finds a better way, I would be happy to get it too

Actually, I’ve tried it too.
I would be happy if it was helpful.

These two examples are attempts to create joints to maintain 90 degree orientation.

The first is a case where the calculation breaks down under the specified conditions.
The second case is one that can always be maintained, but a negative angle cannot be specified.

It may be necessary to know how to express the state of m1 in the coordinate system of m0.

It might be a good idea to request a general-purpose function to find the angle between two objects from the Babylon.js community.

Hello, Mr. @fazil47.

Based on the advice you gave me, I was able to implement the control of the motor and the feedback control probably in a complete form.

It will greatly expand the range of what I can create with Babylon.js.
I appreciate it very much.

I will share what I have implemented.

3 Likes

cc @Cedric

This is a great demo!! I love it

1 Like