Rigibody constraints do not work. Still moves a little.

I have root object with rigibody only and with childrens with colliders. Such a hierarchy is due to the fact that root is spawn point for spawn objects and used to rotate them.

Rigidbody(root)
|-children(collider)
|-children2(collider)
...

The problem is that root rigidbody with constraints (allowed only Y rotation) slightly shifted with each collision of his children with other obstacles. If “Is Kinematic == true” - all ok, coordinates are stable. But I need to rotate my root rigidbody with physics, to stop it if it children ran into obstacles.

Please help me. I have no idea why the restrictions do not work.

113598-1.gif

Solution after several hours of heavy searching and debugging.

private void Start()
{
    // \ (•◡•) /
    Rigidbody rb = target.GetComponent<Rigidbody>();
    rb.centerOfMass = Vector3.zero;
    rb.inertiaTensorRotation = Quaternion.identity;
}

For details read

hmm this has not worked for me.

I was used a hinge joint to create a steering wheel assets that was working very well in Unity 5.6. I imported the asset to 2018.4 with the same configuration but the constraints no longer function as they did in 5.6. I used the above code and several variations to get it to properly constrain position and select rotations but none worked. Not sure what to do…

I tried many things… (I’ve also tried the recommendations here.) It didn’t work. So, I write simple code. I know; It’s a really UGLY method, but absolutely working… Just attach to dynamic object.

public class PositionCorrection : MonoBehaviour
{
    GameObject positionHelper;
    WaitForSeconds phDuration = new WaitForSeconds(1f);

    void Start()
    {
        GameObject positionHelperParent = GameObject.Find("Position Helper Parent");
        if (positionHelperParent == null)
        {
            positionHelperParent = new GameObject("Position Helper Parent");
        }

        positionHelper = new GameObject("P.H. " + gameObject.name);
        positionHelper.transform.SetParent(positionHelperParent.transform);

        StartCoroutine(PositionFix());
    }

    IEnumerator PositionFix()
    {
        while (true)
        {
            if ((positionHelper.transform.position - transform.position).sqrMagnitude < .01f)
            {
                transform.position = positionHelper.transform.position;
            }
            else
            {
                positionHelper.transform.position = transform.position;
            }

            yield return phDuration;
        }
    }
}

I had the same issue with my enemies that using NavMeshAgent . Current solution in the ‘Best Answer’ didnt work for me.

Well after some digging into game, i found out that NavMeshAgent overrides transform.position so upon enemy death, adding this line ‘navMeshAgent.enabled=false;’ solved my problem.