Search Unity

Resolved Animator.deltaRotation value at the RootMotion of the Mirrored animation

Discussion in 'Animation' started by DSivtsov, Dec 2, 2021.

  1. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    151
    Spent some not happy hours before found a solution.
    In case of use the initial animation (Root motion - Right Turn) all was ok the

    deltaRotation += _playerAnimator.deltaRotation.eulerAngles.y;

    (in the Update()) was giving the angle of Player rotation in proceess of Animation.
    But when i started use the mirrored animation (to rotation the Player to Left) I Will began receive the strange delta values (359.96, 359.9, 359.89, 359.86), which on first look doesn't look as delta rotation.
    As was found, the right formula in this case must be

    deltaRotation += _playerAnimator.deltaRotation.eulerAngles.y - 360

    The resulted value will be with sign.
    At eventually i made more universal method
    Code (CSharp):
    1. private const float precision = 0.1f;
    2. public bool WasRotatedOnDemandedAngle()
    3. {
    4.  float sumAgleRotation;
    5.  sumQuaternionRotation *= _playerAnimator.deltaRotation;
    6.  //_sideTurn it's a enum based on Mathf.Sign("AngleTurn")
    7.  sumAgleRotation = (_sideTurn == CtrlHorizontalSpeedInputReader.TurnSide.Left)? 360 - sumQuaternionRotation.eulerAngles.y : sumQuaternionRotation.eulerAngles.y;
    8.  //The first values of deltaRotation in the mirrored animation have a value near 0 +/- 0.04 not the 360.
    9.  //The Mathf.Abs(sumAgleRotation - 360f) > precision) is used to skip this frames
    10.  if (sumAgleRotation > _moduleTurn && Mathf.Abs(sumAgleRotation - 360f) > precision)
    11.      return true;
    12.  else
    13.      return false;
    14.  }
     
    Last edited: Dec 3, 2021