Physics of object attached with points

Hi,

This playground link: https://playground.babylonjs.com/#RGJQAF#7, contains a box attached with two points. Please press ‘r’ and ‘s’ key to rotate the box.

When box is rotated at 45 degree angle, the center of box should move towards left (towards shorter line-length) as per physics.

Is it possible to simulate Physics of the box using any Physics Engine in terms of ‘weight’ and ‘centerOfGravity at 45 degree angle’?

Any reference or suggestion would be helpful.

Thanks.

pinging @Cedric

Hi @dhruv_er

I’m not sure to understand everything.
the center of gravity of the box will not change depending of its orientation.
So, I guess, you want to simulate a (physics) system where the box is oriented 45degree?
And compute the hooks on the box to get 45degrees?

Hi @Cedric

I understand that center of gravity of the box wont change at an angle.

I want to simulate physics system of the box for following:

  • Based on mass & angle, box shifts slightly at an angle. In playground link example https://playground.babylonjs.com/#RGJQAF#7, heavy box slightly shifts towards left in reality. This introduces slack in right line and right line needs to adjusted to remove slack from the actual box. I want to be able to simulate this using physics.

  • Based on physics, calculate location (local center) of box at 45 degree angle. Calculated location shouldn’t give slack in left or right line in reality. Use the location to translate and rotate the box.

  • Identify slack in right line at an angle. Calculate correct line length (from top point to the hook) without having any slack.

You can do the simulation with 2 fixed bodies (with mass = 0), a box impostor and 2 DistanceJoint. Each distance joint connected to the fixed body and to the box. By changing the pivot point, you can change the length of each joint.
Once you know your pivot point, it seems not too much difficult to simulate, without a physics engine, the behavior of the system. The big interest for a physics engine is collision detection.
Your system looks more like a spring system with 1 constraint (box angle).

Hi @Cedric,

On setting box’s mass > 0, box is placed on the fixed point as shown in this link: https://playground.babylonjs.com/#RGJQAF#10.

In the above link, how can we update pivot point to changes length of Distance joints?

Thanks.

You will have to destroy the constraint and create a new one. Physics system are more or less static. You build a system and let it have its own life. If you want to compute a system, then you recreate a new one or you use another method instead of doring iterations.

Hi @Cedric ,

Do I need to destroy 2 DistanceJoints and create a custom joint? if yes, any reference for (1) creating new constraint and (2) the method for computing system, would be helpful.

just want to know, why does the object fall down after calling “object.rotate()” method in this link : https://playground.babylonjs.com/#RGJQAF#22 ? (press ‘r’ key on rendering view to check it)
object has 2 DistanceJoints assigned with maxDistances.

It falls because the pivot is -3 on x and the rotation makes it move a lot more.
without the pivot, I think it looks more like what you want:

physics-massRotationAttachedWithPoints | Babylon.js Playground