Defold Physics Hinge Bug?

attached Hinge to two boxes and set the limit from -60 to -60 angle (yeah, like strongly -60).
In all box2d simulators no rotation of a leg, but here for some reason it has a lot of strange rotations.

In the console I outputed the current angle, there you can see that even once rotated to -60 does not make it stop.

image
here is my structure of project and here is my Hinge creation

physics.create_joint(physics.JOINT_TYPE_HINGE, “torso#collisionobject”, “my_test_joint1”, go.get_position(“anchor_t_leg_left”)*sc, “leg_left#collisionobject”, go.get_position(“anchor_leg_left”)*sc, {enable_limit = true, lower_angle=math.rad(-60),upper_angle = math.rad(-60),reference_angle=0 })

Hi!

I’m not sure what is causing this behavior.
It works at the start (i.e. stays close to 60deg), but then fails. I’m wondering if it breaks somehow, by the torque being applied after it’s thrown?

Afaik, we don’t do anything specific with the joint for Box2D. :thinking:

edit:
What if you alter the reference_angle? I’m not sure about how to set that properly.

2 Likes

image

also here is project

test_hinge.zip (25.9 KB)

3 Likes

Just so happens, we’re building a physics ragdoll using hinge joints and ran into this very same problem.

The hinge respects the limits in rest, but when both bodies are rotated close to 180°, the joint angle seems to break and tries to correct itself the wrong way around. Interestingly, when angular velocity is higher this doesn’t seem to happen.

Sample project:
hinge-joint-test.zip (4.6 KB)

Up / left / right arrows to apply impulse to the ragdoll.

I also ran a minimal test using the box2d extension and wasn’t able to reproduce.

4 Likes

wow, thats great news because after two days of testing in different soft (like R.U.B.E) and with millions of variations in defold ive thought that the problem is on my side.

2 Likes

I created a GH issue to keep track of this.

4 Likes

Hi @Zarkua and @super_kimono
please, turn off this checkbox:

It will help with your issue. We will think if need to change something in the engine to avoid this issue in the future

Thank you very much for your help and examples where I was able to test it!

5 Likes

@AGulev,

Thank you so much for your help! I tried turning off the checkbox as you suggested, and it effectively resolved the issue. It’s great to know that the problem wasn’t with my setup, and your advice pointed me in the right direction. I appreciate the time you took to look into this. Your support and the community’s input have been invaluable.

P.S. i have no idea for what cases this checkbox should be on

3 Likes

Thank you @AGulev!

Ragdoll working perfectly now :slightly_smiling_face:

4 Likes

The setting allows the game objects to set the position onto the collision objects.
Otherwise it’s the collision objects that force the position onto the game object.
This feature was implemented before we had joints, so I think that’s the reason we missed that particular case. We need to figure out a more solid way to allo users to set the position of a gameobject and let the collision object follow.

1 Like

Perhaps we could limit the ability to move collision objects to exclude objects with attached joints?

Perhaps we could limit the ability to move collision objects to exclude objects with attached joints?

I think an overall review of the code needs to be done, with this use case in mind.
I think it should be possible to set the position of a physics object, and then let them simulate.

4 Likes

It might be good to print a warning for now - advising of the setting.

For the review, this is a great idea. It probably only makes sense for kinematic objects to allow setting the position, this doesn’t really make sense for dynamic objects.

1 Like