This topic contains 4 replies, has 2 voices, and was last updated by  prime 2 years, 1 month ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #7344

    sqallpl
    Participant

    Hello,

    I was watching RAIN tutorial called “RAIN{indie} Movement + Mecanim Animation Tutorial” and I’ve noticed that there was a “damp time” parameter in the older version of RAIN.

    I see that damp time is still avaiable in AI MecanimAnimator, but what about MecanimMotor?

    Is it possible to use it or achieve similar effect in the new version and with MecanimMotor?

    At this moment my character rotates very unnatural while walking/running. Variable is send to the Mecanim without any smoothness. It’s 0 and changes to a different number in one frame so it looks jumpy and animation is not blended smoothly into another one.

    In the tutorial that I’ve watched it was possible to smooth this transition by using damp time parameter.

    Can we achieve something similar in the actual version?

    Thanks!

    • This topic was modified 2 years, 1 month ago by  sqallpl.
    • This topic was modified 2 years, 1 month ago by  sqallpl.
    #7680

    sqallpl
    Participant

    Just a little update.

    If it’s any other way to make motor transitions to be smoother please let me know so I can take another approach.

    At this moment when my character rotates, RAIN sends a variable to Mecanim without any delay, so the animation is changed (for example from walkforward to walkforwardright) in one frame. Is there any other method to blend them more natural with RAIN motor and Mecanim?

    Thanks.

    #7690

    prime
    Keymaster

    We usually manage that sort of blending through Mecanim itself (blend trees). Of course, if you prefer you can create a custom mecanim motor. For example, here’s one I created to add extra rotation when a root motion rotation is unable to reach a target:

    using UnityEngine;
    using System.Collections;
    using RAIN.Motion;
    using RAIN.Core;
    using RAIN.Serialization;
    [RAINSerializableClass, RAINElement("Custom Motor")]
    public class CustomMotor : MecanimMotor
    {
        public override void ApplyMotionTransforms()
        {
            //determine if we can make the turn
            base.ApplyMotionTransforms();
            float distanceToTarget = (AI.Kinematic.Position - moveTarget.Position).magnitude;
            float velocity = (AI.Kinematic.PriorSpeed);
            float lastTurnAngleMagnitude = Mathf.Abs(lastTurnAngle);
            if (lastTurnAngleMagnitude > CloseEnoughAngle)
            {
                if ((velocity > 0) && (distanceToTarget > 0))
                {
                    float terminalTurnAngle = (360 * velocity) / ((Mathf.PI + Mathf.PI) * distanceToTarget);
                    if (terminalTurnAngle >= lastTurnAngleMagnitude)
                    {
                        float additive = Mathf.Sign(lastTurnAngle) * (terminalTurnAngle - lastTurnAngleMagnitude) * AI.DeltaTime;
                        AI.Body.transform.Rotate(0f, additive, 0f, Space.World);
                    }
                }
            }
        }
    }
    #7701

    sqallpl
    Participant

    @prime

    Thanks for your reply and script! I appreciate that.

    “We usually manage that sort of blending through Mecanim itself (blend trees). ”

    I’m talking about same approach. I have blend trees set up in Mecanim to blend animations when character is turning left or right. The problem is that RAIN sends a variable to Mecanim and it’s changed there in one frame so it looks jumpy.

    There is a damp time in RAIN’s MecanimAnimator but there is no similar option in MecanimMotor.

    Simple example: My character is running forward, RAIN want to rotate him and the Direction variable is send to Mecanim and changed from 0 to 50 in one frame.
    When RAIN want him to move forward again, Direction variable is changed from 50 to 0 in one frame again.

    Probably I’m doing something wrong, but is there any way to make these transitions to be smoother?

    Thank you.

    #7730

    prime
    Keymaster

    Things you can do:

    1) Create a custom motor as per the script. Add your own damping.
    2) Reduce the turn speed of the Motor.
    3) Change your blending so that, instead of blending based on rotation speed, blend based on turn angle. That way you turn only a little for small turns, and a lot for greater turns.

    We’ll consider adding some damping or similar (we’ve considered using an animation curve to define the rotation and acceleration responses.)

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.