Пример #1
0
    // RollingState = Animator.StringToHash("Ground.Rolling");
    protected void Rolling(float elapsedTime)
    {
        // We only need to set motion settings at the beginning of the animation
        if (!MecanimAnimator.GetBool(MecanimHashes.ClimbLedge))
        {
            return;
        }

        // We need to make sure we know what we're going to roll over.
        if (ActiveHangTarget == null)
        {
            Debug.LogWarning("Failed to have hang target while doing rolling!");
            return;
        }

        // Meta-data about the motion we need to do
        MecanimAnimator.SetBool(MecanimHashes.ClimbLedge, false);
        Bounds ledgeBounds   = ActiveHangTarget.GetComponent <Collider>().bounds;
        float  animationTime = MecanimAnimator.GetCurrentAnimatorStateInfo(0).length;

        // Horizontal motion
        float distanceToMove = Direction.x > 0 ?
                               ledgeBounds.max.x - Controller.bounds.center.x :
                               ledgeBounds.min.x - Controller.bounds.center.x;

        HorizontalSpeed = distanceToMove / animationTime;
        SetMecanimAnimatorHorizontalSpeedFloat();

        // Vertical motion
        float distanceToClimb = ledgeBounds.max.y - Controller.bounds.min.y;

        VerticalSpeed = distanceToClimb / animationTime;
        MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);
    }