Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Multi-Aim Constraint Rotation Limits

Discussion in 'Animation Rigging' started by LightmassGamesDalton, May 9, 2020.

  1. LightmassGamesDalton

    LightmassGamesDalton

    Joined:
    Nov 6, 2017
    Posts:
    4
    Hi,

    Is there a way or will there be a way to set rotation limits per-axis with a min/max angle for using a Multi-Aim Constraint or other constraints?

    I'd like to avoid this:

    rotation_limits_break.gif

    ...Maybe its a feature I should keep maybe not hahah

    But having my player bend too far up, down, left, and right not only looks weird but can cause discontinuities in the rotation as seen above and then all sorts of bad things can happen.

    I am able to use FinalIK angle limits to set a single axis rotation limit per bone while using Animation Rigging but this functionality is fairly limiting as I need multiple axis limits with different min/max values per bone.

    The only other solution I can think of would be to lock my target within some bounds in front of the character but it would be far more pleasurable to just set some rotation limits and call it a day.

    Any ideas?


    Thank you for your time.
     
    Last edited: May 9, 2020
    segant and YondernautsGames like this.
  2. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    196
    I had same problem and took a look to code. I found these lines for twist correction. And pointed where limit can be applied. It's in TwistCorrectionJob.cs

    Code (CSharp):
    1. for (int i = 0; i < twistTransforms.Length; ++i)
    2.                 {
    3.                     ReadWriteTransformHandle twistTransform = twistTransforms[i];
    4.  
    5.                     float twistWeight = Mathf.Clamp(weightBuffer[i], -1f, 1f);
    6.                     Quaternion rot = Quaternion.Lerp(Quaternion.identity, Mathf.Sign(twistWeight) < 0f ? invTwistRot : twistRot, Mathf.Abs(twistWeight));
    7.                    //Here rotation limit function can be implemented.
    8.                     twistTransform.SetLocalRotation(stream, Quaternion.Lerp(twistBindRotations[i], rot, w));
    9.  
    10.                     // Required to update handles with binding info.
    11.                     twistTransforms[i] = twistTransform;
    12.                 }
    For you MultiAimConstraintJob before line 110 you can limit it which is this line. So you may limit it after lerp or before lerp. It's up to you to handle that. But really it should be in stock code. Because there are lots of interfaces going on.
    Code (CSharp):
    1. driven.SetLocalRotation(stream, Quaternion.Lerp(drivenLRot, newRot, w));
     
    Last edited: May 11, 2020
    LightmassGamesDalton likes this.
  3. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    196
    I just decompiled some data from dll and created similar interface to it. So now trying to limit it.
     
  4. LightmassGamesDalton

    LightmassGamesDalton

    Joined:
    Nov 6, 2017
    Posts:
    4
    Thanks for the lead Segant!

    I found a way to use the FinalIK rotation angle limits more cleverly for my use-case that has solved the problem for now. My time is pretty limited so I'll keep working on other tasks and maybe when I revisit another quality-pass there might be more functionality exposed by the rigging package.
     
  5. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    196
    I have done it via copying 3 cs file and changing them as I wanted.
     
    ProceduralCatMaker likes this.
  6. segant

    segant

    Joined:
    May 3, 2017
    Posts:
    196
    Files are mainscript, editor script of main script and job script
    upload_2020-5-12_20-16-19.png
     
    Last edited: May 12, 2020