Search Unity

Freeze rigidbody rotation by custom vector direction

Discussion in 'Physics' started by xVergilx, Oct 3, 2019.

  1. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Is there a way to do this? Or maybe a clever workaround?

    What I need is to freeze the rotation, so that forward (Z) and up (Y) are always constrained to the custom vector.

    Using worldspace constraints works, but I need to constrain rigidbody to some custom supplied vectors of up and forward (e.g. add torque on X and prevent it from rolling away to the different direction).

    Manual control via FixedUpdate + .MoveRotation() is the only option, right?
     
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Okay, so this turns out to be quite easy to do.

    Rigidbody's actually only translated in world space, where as rotation is local space aligned.
    I've had it attached as a child to other gameobject that's why it behaved weirdly when rotating / constraining.

    Unparenting and rotating the rigidbody correctly once did the trick for me.