#Joints are acting strange

1 messages · Page 1 of 1 (latest)

cerulean sigil
#

Whenever I add a new HingeJoint2D (or any joint for that matter) component on any object and connect it to another rigidbody through a script, it doesn't fully connect the two objects together in a way that's hard to explain. It's like there's some sort of distance set between the two objects before they can interact with the hinge. Does anyone know what the issue is and how I could solve it?

#

If my explanation is insufficient I'd be happy to send a screenshot or recording

cerulean sigil
# fallow quest Show your code? Are you setting all of these properly? https://docs.unity3d.com...
using UnityEngine.InputSystem;

public class NewGrabController : MonoBehaviour
{
    [SerializeField] private GameObject grabbingTarget;
    private bool isGrabbing = false;

    private void OnCollisionEnter2D(Collision2D col)
    {
        grabbingTarget = col.gameObject;
    }

    private void OnCollisionExit2D(Collision2D col)
    {
        if (isGrabbing) return;

        if (col.gameObject == grabbingTarget)
        {
            grabbingTarget = null;
        }
    }

    public void Grab(InputAction.CallbackContext context)
    {
        if (grabbingTarget != null && context.performed)
        {
            isGrabbing = true;
            Rigidbody2D rb = grabbingTarget.GetComponent<Rigidbody2D>();
            if (rb != null)
            {
                HingeJoint2D hingeJoint = gameObject.AddComponent(typeof(HingeJoint2D)) as HingeJoint2D;
                hingeJoint.connectedBody = rb;
                hingeJoint.breakForce = 1200;
            }
        }
        if (!context.performed && GetComponent<HingeJoint2D>() != null)
        {
            Destroy(GetComponent<HingeJoint2D>());
            isGrabbing = false;
        }
    }
}```
#

This is meant to be a grab script for an active ragdoll

fallow quest
cerulean sigil
fallow quest
#

If you don't, it will be attached at the pivot point of each object (local 0,0,0)

cerulean sigil
#

the problem is the joint doesn't seem to attach to either of the two objects properly. They kinda "pull" each other together as if a grappling hook was being pulled but they don't "connect"

cerulean sigil