# Defold Physics Hinge Bug?

**URL:** <https://forum.defold.com/t/defold-physics-hinge-bug/75745>\
**Category:** Bugs\
**Created:** [January 22, 2024, 5:09am UTC](https://forum.defold.com/t/defold-physics-hinge-bug/75745 "2024-01-22T05:09:13Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zarkua](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/zarkua/32/40015_2.png) [@Zarkua](https://forum.defold.com/u/Zarkua)\
**Post date:** [January 22, 2024, 5:09am UTC](https://forum.defold.com/t/defold-physics-hinge-bug/75745/1 "2024-01-22T05:09:13Z")

</div>

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](https://forum-defold-uploads.b-cdn.net/original/3X/f/a/fab70e267bee5d04c8fbc1631631bc872a75f202.png)  
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 })

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [January 22, 2024, 9:12am UTC](https://forum.defold.com/t/defold-physics-hinge-bug/75745/2 "2024-01-22T09:12:16Z")

</div>

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. 🤔

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

---

<div class="post-metadata">

**Author:** ![Zarkua](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/zarkua/32/40015_2.png) [@Zarkua](https://forum.defold.com/u/Zarkua)\
**Post date:** [January 22, 2024, 10:10am UTC](https://forum.defold.com/t/defold-physics-hinge-bug/75745/3 "2024-01-22T10:10:47Z")

</div>

> [@Mathias\_Westerdahl](#):
>
> What if you alter the reference\_angle? I’m not sure about how to set that properly.

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/e/9/e997ab46788f3a5c5567993492cc36299d97da79.png)

also here is project

[test\_hinge.zip](https://forum.defold.com/uploads/short-url/oaQFpjKf6bOSzuFAX6UG7iRuWw8.zip) (25.9 KB)

---

<div class="post-metadata">

**Author:** ![super\_kimono](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/super_kimono/32/34642_2.png) [@super\_kimono](https://forum.defold.com/u/super_kimono)\
**Post date:** [January 22, 2024, 12:02pm UTC](https://forum.defold.com/t/defold-physics-hinge-bug/75745/4 "2024-01-22T12:02:05Z")

</div>

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](https://forum.defold.com/uploads/short-url/OPgHZCTne0Rhu1RnbA897O3IKx.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.

---

<div class="post-metadata">

**Author:** ![Zarkua](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/zarkua/32/40015_2.png) [@Zarkua](https://forum.defold.com/u/Zarkua)\
**Post date:** [January 22, 2024, 12:13pm UTC](https://forum.defold.com/t/defold-physics-hinge-bug/75745/5 "2024-01-22T12:13:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [January 22, 2024, 6:37pm UTC](https://forum.defold.com/t/defold-physics-hinge-bug/75745/6 "2024-01-22T18:37:03Z")

</div>

I created a GH issue to keep track of this.

[https://github.com/defold/defold/issues/8438](https://github.com/defold/defold/issues/8438)

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [January 24, 2024, 7:45pm UTC](https://forum.defold.com/t/defold-physics-hinge-bug/75745/7 "2024-01-24T19:45:59Z")

</div>

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

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/d/2/d25d37d1d7703981cce41d85ed5f65a562b998a2.png)

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!

---

<div class="post-metadata">

**Author:** ![Zarkua](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/zarkua/32/40015_2.png) [@Zarkua](https://forum.defold.com/u/Zarkua)\
**Post date:** [January 24, 2024, 8:20pm UTC](https://forum.defold.com/t/defold-physics-hinge-bug/75745/8 "2024-01-24T20:20:41Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![super\_kimono](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/super_kimono/32/34642_2.png) [@super\_kimono](https://forum.defold.com/u/super_kimono)\
**Post date:** [January 25, 2024, 12:02pm UTC](https://forum.defold.com/t/defold-physics-hinge-bug/75745/9 "2024-01-25T12:02:38Z")

</div>

Thank you @AGulev!

Ragdoll working perfectly now 🙂

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [January 25, 2024, 12:22pm UTC](https://forum.defold.com/t/defold-physics-hinge-bug/75745/10 "2024-01-25T12:22:49Z")

</div>

> [@Zarkua](#):
>
> P.S. i have no idea for what cases this checkbox should be on

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.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [January 25, 2024, 1:26pm UTC](https://forum.defold.com/t/defold-physics-hinge-bug/75745/11 "2024-01-25T13:26:49Z")

</div>

> [@Mathias\_Westerdahl](#):
>
> 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.

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

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [January 25, 2024, 1:30pm UTC](https://forum.defold.com/t/defold-physics-hinge-bug/75745/12 "2024-01-25T13:30:39Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![Jay](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jay/32/35079_2.png) [@Jay](https://forum.defold.com/u/Jay)\
**Post date:** [February 20, 2024, 9:23pm UTC](https://forum.defold.com/t/defold-physics-hinge-bug/75745/13 "2024-02-20T21:23:33Z")

</div>

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.
