freezeRotation = false; removes all rotational constraints, possible fix

freezeRotation = false; removes all rotational constraints
this seems like it was an oversight, So i tried fixing it with some googling help.
what i did was to add in a long and complicated line of code with “pipes” afterwards, this however feels a little messy and long, is there a way to shorten it? is there maybe something i missed out on that prevents the freezeRotation = false line from removing what had been set previously in the editor?

Heres the line i added :

rb.constraints =
RigidbodyConstraints.FreezeRotationX|RigidbodyConstraints.FreezeRotationY|RigidbodyConstraints.FreezePositionZ;

1 Like

This is what I could come up with.

public class FreezeRotations : MonoBehaviour
{
    [SerializeField] Rigidbody freezeConstraints;

    void Start()
    {
        FreezeRotation(true);
    }

    bool FreezeRotation(bool result)
    {
        return freezeConstraints.freezeRotation = result;
    }
}

This will freeze all rotations on true or unfreeze them on false.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms