HingeJoint2D without rotating collider

Hi all :slight_smile:

I’m working on a 2D swinging/grappling game using HingeJoint2D.

I have a GameObject with a Rigidbody2D attached and a script which creates a HingeJoint2D component at run time. As long as you hold down the mouse button you would swing off the ceiling of the level. While the GameObject is swinging, the sprite and collider attached is rotating in orientation to the grapple point.

I’ve tried countering this by separating the sprite and collider as a separate GameObject attached as a child of the main GameObject and applying transform.rotation = Quaternion.identity to stop the rotation as it would otherwise use the rotation of the parent GameObject, and this semi works most of the time until I start colliding with things, and the GameObject would start just going crazy, defying its gravity or gets a constant upwards force for some reason.

I also tried just separating the sprite+collider completely (not parented) and just keep the two positions together in script, however this of course can’t work as the collider needs to be attached to the rigidbody (or at least as a child object) otherwise collisions cannot occur.

How should I do this?:face_with_spiral_eyes:

First of all I really hope you are making this game :wink:

Anyway, it sounds like you are connecting the player directly to the ceiling. I suggest you try adding an extra rigidbody between the player and the ceiling. Therefore, connect the player to the extra rigidbody via HingeJoint2D (Limits disabled). Then connect the extra rigidbody to the ceiling via HingeJoint2D (Limits disabled).

You will notice much more free motion when 3 rigidbodies are conencted via hingejoints rather than 2 rigidbodies connected via hingejoints.