示例#1
0
    //ClimbingStrafeState = Animator.StringToHash ("Climbing.ClimbingStrafe");
    //  protected void ClimbingStrafe(float elapsedTime)
    //  {
    //      if(ActiveHangTarget == null) {
    //          DropHangTarget();
    //          MecanimAnimator.SetBool(MecanimHashes.Fall, true);
    //          return;
    //      }
    //
    //      ApplyClimbingStrafing(CharInput.Horizontal);
    //
    //      if(HorizontalSpeed != 0)
    //          ApplyClimbingVertical(vertical);
    //      else
    //          VerticalSpeed = 0.0f;
    //
    //      if(ActiveHangTarget.DoesFaceZAxis())
    //          Direction = Vector3.zero;
    //
    //      MecanimAnimator.SetBool(MecanimHashes.Jump, CharInput.JumpPressed);
    //
    //  }

    // WallgrabbingState = Animator.StringToHash("Wall.Wallgrabbing");
    protected void Wallgrabbing(float elapsedTime)
    {
        // We don't move horizontally
        HorizontalSpeed = 0;
        SetMecanimAnimatorHorizontalSpeedFloat();

        // But we do want to start moving down the wall
        if (_wallJumpCount > 0 || TimeInCurrentState > Settings.WallgrabDuration)
        {
            VerticalSpeed = Settings.WallSlideSpeed * elapsedTime;
        }
        else
        {
            VerticalSpeed = 0;
        }
        VerticalSpeed = 0;
        MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);

        // You can let go of the wall
        if (CharInput.PickupPressed)
        {
            MecanimAnimator.SetBool(MecanimHashes.Fall, true);
            MecanimAnimator.SetBool(MecanimHashes.GrabWall, false);
            DropHangTarget();

            // But the expectation is that you will jump off
        }
        else if (CharInput.JumpPressed)
        {
            MecanimAnimator.SetBool(MecanimHashes.JumpWall, true);
            MecanimAnimator.SetBool(MecanimHashes.GrabWall, false);
            DropHangTarget();
        }
    }
示例#2
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);
    }
示例#3
0
    // FallingState = Animator.StringToHash("Air.Falling");
    protected void Falling(float elapsedTime)
    {
        // Maintain horizontal speed by default, but allow 1/2 the normal movement for horizontal input
        if (CharInput.Right || CharInput.Left)
        {
            ApplyMovingHorizontal(elapsedTime * 0.5f);
        }

        // Vertical Motion
        ApplyGravity(elapsedTime);
        MecanimAnimator.SetBool(MecanimHashes.Fall, false);

        // You can grab onto the walls while falling
        MecanimAnimator.SetBool(MecanimHashes.GrabWall, CanGrabWall);

        // You can regrab the hangable object you last let go of
        if (!(ActiveHangTarget is Ledge && ((Ledge)ActiveHangTarget).Obstacle) &&
            (CanHangOffObject && ActiveHangTarget.DoesFaceXAxis() && VerticalSpeed < 0) ||
            (CanHangOffObject && ActiveHangTarget.DoesFaceZAxis() && CharInput.Up))
        {
            MecanimAnimator.SetBool(MecanimHashes.Hang, true);
            VerticalSpeed   = 0;
            HorizontalSpeed = 0;
            SetMecanimAnimatorHorizontalSpeedFloat();
            MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);
        }
        else
        {
            MecanimAnimator.SetBool(MecanimHashes.Hang, false);
        }
    }
示例#4
0
    protected override void UpdateMecanimVariables()
    {
        if (IgnoreXYMovement)
        {
            return;
        }

        if (!MecanimAnimator.GetBool(MecanimHashes.Jump) && IsGrounded && CharInput.JumpPressed)
        {
            MecanimAnimator.SetBool(MecanimHashes.Jump, true);
        }

        bool facingRightLadder = (ActiveHangTarget && ActiveHangTarget.transform.position.x - transform.position.x > 0.0f);
        bool facingLeftLadder  = (ActiveHangTarget && transform.position.x - ActiveHangTarget.transform.position.x > 0.0f);

        bool startClimbLadder = CanClimbLadder && ((facingRightLadder && CharInput.Right) ||
                                                   (facingLeftLadder && CharInput.Left));

        MecanimAnimator.SetBool(MecanimHashes.ClimbLadder, startClimbLadder);

        /*
         * if(startClimbLadder)
         *  _autoClimbDir = AutoClimbDirection.AutoClimb_Up;
         * // if not in a climb, reset our auto-climb direction for use next climb.
         * if(  (CurrentState.fullPathHash != ClimbingLadderState || CurrentState.fullPathHash != ClimbingPipeState) )
         *  _autoClimbDir = AutoClimbDirection.AutoClimb_None;
         */

        MecanimAnimator.SetBool(MecanimHashes.ClimbRope, CanClimbRope);

        MecanimAnimator.SetBool(MecanimHashes.IsGrounded, IsGrounded);

        MecanimAnimator.SetBool(MecanimHashes.AttackHorizontal, CharInput.Attack > 0);
        MecanimAnimator.SetBool(MecanimHashes.AttackVertical, CharInput.Attack < 0);

        if (!IsGrounded)
        {
            MecanimAnimator.SetBool(MecanimHashes.AcquiringTarget, false);
        }

        // Give Olympus some perfectly hard stops on land
        if (IsLanding)
        {
            HorizontalSpeed = 0;
        }

        // Knowing direction is useful for the turnaround animation
        MecanimAnimator.SetFloat(MecanimHashes.XDirection, Direction.x);

        // Olympus needs to turn off the screens when moving
        // TODO: THINK OF A MORE EFFICIENT WAY INSTEAD OF DOING THIS EVERY FRAME
        if (CharInput.Left || CharInput.Right)
        {
            foreach (Fader screen in IdleScreens)
            {
                screen.FadeOut();
            }
        }
    }
示例#5
0
 public override void MakeDamaged(Vector3 knockForce)
 {
     MecanimAnimator.SetBool(MecanimHashes.Damaged, true);
     HorizontalSpeed = knockForce.x;
     VerticalSpeed   = knockForce.y;
     SetMecanimAnimatorHorizontalSpeedFloat();
     MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);
 }
示例#6
0
    // JumpingState = Animator.StringToHash("Jumping.Jumping");
    // FrontflipState = Animator.StringToHash("Jumping.Frontflip");
    // FrontflipLoopState = Animator.StringToHash("Jumping.FrontflipLoop");
    protected void Jumping(float elapsedTime)
    {
        // We only determine vertical speed (Horizontal Speed is maintained throughout the jump)
        if (MecanimAnimator.GetBool(MecanimHashes.Jump))
        {
            float jumpHeight = Settings.JumpHeight;
            if (CurrentState.fullPathHash == FrontflipState)
            {
                jumpHeight *= 1.5f;
            }
            VerticalSpeed = Mathf.Sqrt(2 * jumpHeight * Settings.Gravity);
            MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);
            MecanimAnimator.SetBool(MecanimHashes.Jump, false);
        }
        else
        {
            ApplyGravity(elapsedTime);
        }

        // You can increase horizontal speed midair ONLY if doing a sneak jump and you weren't already at max speed
        if (CurrentState.fullPathHash == JumpingState && (CharInput.Left || CharInput.Right))
        {
            float prevSpeed = HorizontalSpeed;
            ApplyMovingHorizontal(elapsedTime * 0.5f);
            if (Mathf.Abs(HorizontalSpeed) < Mathf.Abs(prevSpeed))
            {
                HorizontalSpeed = prevSpeed;
            }
            else if (Direction.x > 0 && HorizontalSpeed > 0.79f * Settings.MaxHorizontalSpeed)
            {
                HorizontalSpeed = 0.79f * Settings.MaxHorizontalSpeed;
            }
            else if (Direction.x < 0 && HorizontalSpeed < -0.79f * Settings.MaxHorizontalSpeed)
            {
                HorizontalSpeed = -0.79f * Settings.MaxHorizontalSpeed;
            }
            SetMecanimAnimatorHorizontalSpeedFloat();
        }

        // You can grab onto walls while jumping
        MecanimAnimator.SetBool(MecanimHashes.GrabWall, CanGrabWall);

        // You can hang off most objects while jumping
        bool shouldHang = (CanHangOffObject && ActiveHangTarget.DoesFaceXAxis() && VerticalSpeed < 0) ||
                          (CanHangOffObject && ActiveHangTarget.DoesFaceZAxis() && CharInput.Up);

        MecanimAnimator.SetBool(MecanimHashes.Hang, shouldHang);

        // You can re-grab ropes you just let go of
        bool shouldRegrabRope = CharInput.Up && PreviousHangTarget != null && PreviousHangTarget.GetComponent <Collider>().bounds.Contains(transform.position);

        if (shouldRegrabRope)
        {
            AddHangTarget(PreviousHangTarget);
            MecanimAnimator.SetBool(MecanimHashes.ClimbRope, true);
        }
    }
示例#7
0
    // StealthKillState = Animator.StringToHash("Combat.Stealth Kill");
    protected void StealthKill(float elapsedTime)
    {
        MecanimAnimator.SetBool(MecanimHashes.StealthKill, false);

        // This is a completely stationary action
        HorizontalSpeed = 0.0f;
        VerticalSpeed   = 0.0f;
        SetMecanimAnimatorHorizontalSpeedFloat();
        MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);
    }
示例#8
0
    // LandingState = Animator.StringToHash("Landing.Landing");
    // LandSneakState = Animator.StringToHash("Landing.SneakLanding");
    // LandHighState = Animator.StringToHash("Landing.HighLanding");
    // LandRollState = Animator.StringToHash("Landing.Rolling");
    protected void Landing(float elapsedTime)
    {
        // We do hard stops on land unless we're rolling
        if (TimeInCurrentState == 0)
        {
            if (CurrentState.fullPathHash == LandHighState || (CurrentState.fullPathHash != LandRollState && !(CharInput.Left || CharInput.Right)))
            {
                HorizontalSpeed = 0;
            }
            else if (CurrentState.fullPathHash != LandRollState)
            {
                HorizontalSpeed *= 0.5f;
            }
            else
            {
                ApplyFriction(elapsedTime);
            }
            SetMecanimAnimatorHorizontalSpeedFloat();
        }

        // Horizontal Motion mainly wants us to slow down
        if (CurrentState.fullPathHash != LandHighState && InputMoveForward)
        {
            ApplyMovingHorizontal(elapsedTime * 0.5f);
        }
        else
        {
            if (CurrentState.fullPathHash == LandRollState)
            {
                elapsedTime *= 1.5f;
            }
            ApplyFriction(elapsedTime);
        }

        // Vertical Motion depends on whether we're on the ground
        if (!IsGrounded)
        {
            if (CurrentState.fullPathHash != LandRollState || CurrentState.normalizedTime > 0.99f)
            {
                MecanimAnimator.SetBool(MecanimHashes.Fall, true);
            }
            else
            {
                ApplyGravity(elapsedTime);
            }
        }
        else
        {
            VerticalSpeed = GroundVerticalSpeed;
            MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, GroundVerticalSpeed);
        }

        // You can jump again even before you finish landing
        AllowGroundJump();
    }
示例#9
0
    // DeathState = Animator.StringToHash("Combat.Death");
    // DeadState = Animator.StringToHash("Combat.Waiting For Respawn");
    protected void Die(float elapsedTime)
    {
        if (IsGrounded)
        {
            ApplyFriction(elapsedTime);
            VerticalSpeed = GroundVerticalSpeed;
            MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);
        }
        else
        {
            ApplyGravity(elapsedTime);
        }

        MecanimAnimator.SetBool(MecanimHashes.Jump, false);
        MecanimAnimator.SetBool(MecanimHashes.Fall, false);
        MecanimAnimator.SetBool(MecanimHashes.Die, false);
    }
示例#10
0
    // WalljumpingState = Animator.StringToHash("Wall.Walljumping");
    protected void Walljumping(float elapsedTime)
    {
        // Determine motion on the first frame
        if (MecanimAnimator.GetBool(MecanimHashes.JumpWall))
        {
            Direction       = -Direction;
            HorizontalSpeed = Settings.MaxHorizontalSpeed * Direction.x * 0.79f;
            SetMecanimAnimatorHorizontalSpeedFloat();
            VerticalSpeed = Mathf.Sqrt(2 * Settings.JumpHeight * Settings.Gravity);
            MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);
            _wallJumpCount++;
            MecanimAnimator.SetBool(MecanimHashes.JumpWall, false);
        }
        else
        {
            ApplyGravity(elapsedTime);
        }

        // You eventually start falling down
        if (transform.position.y >= LastGroundHeight - 1)
        {
            MecanimAnimator.SetBool(MecanimHashes.Fall, false);
        }

        // You can do consecutive wall grabs/jumps
        if (CanGrabWall)
        {
            MecanimAnimator.SetBool(MecanimHashes.GrabWall, true);
        }

        // You can grab onto ledges
        if (!(ActiveHangTarget is Ledge && ((Ledge)ActiveHangTarget).Obstacle) &&
            (CanHangOffObject && ActiveHangTarget.DoesFaceXAxis() && VerticalSpeed < 0) ||
            (CanHangOffObject && ActiveHangTarget.DoesFaceZAxis() && CharInput.Up))
        {
            MecanimAnimator.SetBool(MecanimHashes.Hang, true);
            VerticalSpeed = 0;
            MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);
            HorizontalSpeed = 0;
        }
        else
        {
            MecanimAnimator.SetBool(MecanimHashes.Hang, false);
        }
    }
示例#11
0
    // PickupState = Animator.StringToHash("Kneeling.Pickup");
    protected void Pickup(float elapsedTime)
    {
        // Everything relevant happens on the first frame
        if (MecanimAnimator.GetBool(MecanimHashes.Pickup))
        {
            MecanimAnimator.SetBool(MecanimHashes.Pickup, false);

            // Horizontal Motion
            HorizontalSpeed = 0;
            SetMecanimAnimatorHorizontalSpeedFloat();

            // Vertical Motion
            VerticalSpeed = GroundVerticalSpeed;
            MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);

            // Pickup a weapon
            if (_itemPickedup.WeaponPrefab != null)
            {
                int    pickupCount    = _itemPickedup.Quantity;
                Weapon pickedUpWeapon = _itemPickedup.WeaponPrefab.GetComponent <Weapon>();
                if (!GameManager.Inventory.TryAddAmmo(pickedUpWeapon, pickupCount))
                {
                    // NOTE: DON'T USE THE OBJECT POOL BECAUSE IT DOESN'T REALLY HAPPEN THAT OFTEN
                    Transform instantiatedWeapon = (Transform)Instantiate(_itemPickedup.WeaponPrefab);
                    Weapon    newWeapon          = instantiatedWeapon.GetComponent <Weapon>();
                    newWeapon.Quantity = pickupCount;
                    GameManager.Inventory.Weapons.Add(newWeapon);
                    GameManager.UI.CycleToNextWeapon();
                }
                GameManager.UI.RefreshWeaponWheel();

                // Pickup an inventory item
            }
            else
            {
                InventoryItem newInvItem = InventoryItemFactory.CreateFromType(_itemPickedup.Type, _itemPickedup.Quantity);
                GameManager.Inventory.AddItem(newInvItem);
                GameManager.UI.CraftingMenu.RefreshItemWheel();
            }

            // Get rid of the picked up item
            Destroy(_itemPickedup.gameObject, 0.5f);
        }
    }
示例#12
0
    // IdleState = Animator.StringToHash("Base Layer.Idle");
    protected virtual void Idle(float elapsedTime)
    {
        // Switch between crouching and standing idles based off enemies that could hear
        float idleNum    = MecanimAnimator.GetFloat(MecanimHashes.IdleNum);
        float targetIdle = GameManager.AI.EnemiesCouldHear > 0 ? 1 : 0;

        idleNum = Mathf.Lerp(idleNum, targetIdle, elapsedTime * IdleChangeSpeed);
        MecanimAnimator.SetFloat(MecanimHashes.IdleNum, idleNum);

        // You can start moving left or right at any point
        ApplyMovingHorizontal(elapsedTime);
        ApplyBiDirection();

        // You stick to the ground
        VerticalSpeed = GroundVerticalSpeed;
        MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);

        // You could potentially fall down if the ground disappears beneath you
        MecanimAnimator.SetBool(MecanimHashes.Fall, !IsGrounded);

        // You can only pickup items while in idle
        if (CharInput.Pickup)
        {
            GameObject itemObj   = null;
            bool       canPickup = CanPickupItem(out itemObj);
            if (canPickup && itemObj != null)
            {
                _itemPickedup = itemObj.GetComponent <Item>();
            }
            MecanimAnimator.SetBool(MecanimHashes.Pickup, canPickup && _itemPickedup != null);
        }

        // You can re-grab ropes you just let go of
        bool shouldRegrabRope = CharInput.Up && PreviousHangTarget != null && PreviousHangTarget.GetComponent <Collider>().bounds.Contains(transform.position);

        if (shouldRegrabRope)
        {
            AddHangTarget(PreviousHangTarget);
            MecanimAnimator.SetBool(MecanimHashes.ClimbRope, true);
        }

        // You can jump
        AllowGroundJump();
    }
示例#13
0
    // BackflipState = Animator.StringToHash("Air.Backflip");
    protected void Backflip(float elapsedTime)
    {
        // We determine our target speed on the first frame of the action
        if (MecanimAnimator.GetBool(MecanimHashes.Backflip))
        {
            MecanimAnimator.SetBool(MecanimHashes.Backflip, false);
            _desiredDirectionX = -Direction.x;
            _desiredSpeed      = -HorizontalSpeed;
            VerticalSpeed      = Mathf.Sqrt(2 * Settings.JumpHeight * 1.5f * Settings.Gravity);
            MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);
        }
        else
        {
            ApplyGravity(elapsedTime);
        }

        // Adjust horizontal speed frame by frame
        float accelerationSmoothing = Settings.HorizontalAcceleration * elapsedTime;

        if (TimeInCurrentState > 0.15f)
        {
            Vector3 newDir = new Vector3(Mathf.Lerp(Direction.x, _desiredDirectionX, accelerationSmoothing), 0, 0);
            if (newDir.x * Direction.x < 0)
            {
                HorizontalSpeed = -HorizontalSpeed;
            }
            Direction = newDir;
        }
        accelerationSmoothing = Settings.HorizontalAcceleration * elapsedTime;
        HorizontalSpeed       = Mathf.Lerp(HorizontalSpeed, _desiredSpeed, accelerationSmoothing);
        SetMecanimAnimatorHorizontalSpeedFloat();

        // You can grab onto objects even in the middle of a backflip
        bool shouldHang = (CanHangOffObject && ActiveHangTarget.DoesFaceXAxis() && VerticalSpeed < 0) ||
                          (CanHangOffObject && ActiveHangTarget.DoesFaceZAxis() && CharInput.Up);

        MecanimAnimator.SetBool(MecanimHashes.Hang, shouldHang);

        // Make sure we don't enter the other Air states
        MecanimAnimator.SetBool(MecanimHashes.Jump, false);
        MecanimAnimator.SetBool(MecanimHashes.Fall, false);
    }
示例#14
0
    // RunningState = Animator.StringToHash("Ground.Running");
    protected void Locomotion(float elapsedTime)
    {
        // You run left or right
        ApplyMovingHorizontal(elapsedTime);
        ApplyBiDirection();

        // You stick to the ground
        VerticalSpeed = GroundVerticalSpeed;
        MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);

        // You could potentially fall down by running off a ledge
        MecanimAnimator.SetBool(MecanimHashes.Fall, !IsGrounded);

        // You could start rolling over small obstacles in your way
        MecanimAnimator.SetBool(MecanimHashes.ClimbLedge,
                                ActiveHangTarget != null && ActiveHangTarget is Ledge && ((Ledge)ActiveHangTarget).Obstacle &&
                                ((Direction.x > 0 && ((Ledge)ActiveHangTarget).Left) || (Direction.x < 0 && !((Ledge)ActiveHangTarget).Left)));

        // You can re-grab ropes you just let go of
        bool shouldRegrabRope = CharInput.Up && PreviousHangTarget != null && PreviousHangTarget.GetComponent <Collider>().bounds.Contains(transform.position);

        if (shouldRegrabRope)
        {
            AddHangTarget(PreviousHangTarget);
            MecanimAnimator.SetBool(MecanimHashes.ClimbRope, true);
        }

        // You can only do a backflip if you're running
        if (!IsSneaking && ((Direction.x > 0 && CharInput.JumpLeft) || (Direction.x < 0 && CharInput.JumpRight)))
        {
            MecanimAnimator.SetBool(MecanimHashes.Backflip, true);
            MecanimAnimator.SetBool(MecanimHashes.Jump, false);

            // You can do a jump
        }
        else
        {
            AllowGroundJump();
            MecanimAnimator.SetBool(MecanimHashes.Backflip, false);
        }
    }
示例#15
0
    protected void ClimbingVertical(float elapsedTime)
    {
        if (ActiveHangTarget == null)
        {
            DropHangTarget();
            MecanimAnimator.SetBool(MecanimHashes.Fall, true);
            return;
        }

        HorizontalSpeed = 0;

        float vertical = CharInput.Vertical;

        ApplyClimbingVertical(vertical);

        if (ActiveHangTarget.DoesFaceZAxis())
        {
            Direction = Vector3.zero;
        }

        MecanimAnimator.SetFloat(MecanimHashes.HorizontalSpeed, HorizontalSpeed);
        MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);

        if (CharInput.InteractionPressed)
        {
            MecanimAnimator.SetBool(MecanimHashes.Fall, true);
            DropHangTarget();
            return;
        }
        else
        {
            MecanimAnimator.SetBool(MecanimHashes.Fall, false);
        }

        if (CharInput.JumpActive)
        {
            MecanimAnimator.SetBool(MecanimHashes.Jump, true);
            DropHangTarget();
        }
    }
示例#16
0
    // ClimbingLedgeState = Animator.StringToHash("Climbing.ClimbingLedge");
    protected void ClimbingLedge(float elapsedTime)
    {
        // Make sure we actually have a ledge to climb up
        if (_ledge == null)
        {
            Debug.LogWarning("Player Character's Ledge Not Found!");
            MecanimAnimator.SetBool(MecanimHashes.Fall, true);
            return;
        }

        // The motion for climbing ledges is somewhat complicated...
        if ((Direction.x > 0 && transform.position.x > _ledge.transform.position.x + _ledge.GetComponent <Collider>().bounds.extents.x) ||
            (Direction.x < 0 && transform.position.x < _ledge.transform.position.x - _ledge.GetComponent <Collider>().bounds.extents.x) ||
            CurrentState.normalizedTime > 0.9)
        {
            MecanimAnimator.SetBool(MecanimHashes.ClimbLedge, false);
            VerticalSpeed = GroundVerticalSpeed;
        }
        else if (transform.position.y > _ledge.transform.position.y + _ledge.GetComponent <Collider>().bounds.extents.y + Height / 2)
        {
            VerticalSpeed = 0;
        }
        else
        {
            if (_ledge.DoesFaceZAxis())
            {
                HorizontalSpeed = 0.0f;
                VerticalSpeed   = Settings.LedgeClimbingSpeed;
            }
            else if (_ledge.DoesFaceXAxis())
            {
                HorizontalSpeed = Direction.x * Settings.LedgeClimbingSpeed;
                VerticalSpeed   = Settings.LedgeClimbingSpeed;
            }
        }
        SetMecanimAnimatorHorizontalSpeedFloat();
        MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);
        MecanimAnimator.SetBool(MecanimHashes.Fall, false);
    }
示例#17
0
    // HangingState = Animator.StringToHash("Climbing.Hanging");
    protected void Hanging(float elapsedTime)
    {
        // Make sure we actually have something to hang on
        if (ActiveHangTarget == null)
        {
            DropHangTarget();
            MecanimAnimator.SetBool(MecanimHashes.Fall, true);
            Debug.LogWarning("Player lost track of hang target and fell!");
            return;
        }

        // We determine all our motion on the first frame
        if (MecanimAnimator.GetBool(MecanimHashes.Hang))
        {
            if (ActiveHangTarget.DoesFaceZAxis())
            {
                HorizontalSpeed = 0.0f;
                Direction       = Vector3.zero;
            }
            else
            {
                HorizontalSpeed = Direction.x * Settings.LedgeClimbingSpeed;
                if (IsHangTargetToRight)
                {
                    Direction = Vector3.right;
                }
                else
                {
                    Direction = Vector3.left;
                }
            }
            SetMecanimAnimatorHorizontalSpeedFloat();
            VerticalSpeed = 0;
            MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);
            MecanimAnimator.SetBool(MecanimHashes.Hang, false);
        }

        // Stay on whatever we're hanging on, even if it's moving
        ActivePlatform = ActiveHangTarget.transform;
        MecanimAnimator.SetBool(MecanimHashes.Fall, false);

        // You can press up/forward on ledges to climb up
        if (ActiveHangTarget is Ledge && (CharInput.Up || InputMoveForward))
        {
            _ledge = ActiveHangTarget as Ledge;
            MecanimAnimator.SetBool(MecanimHashes.ClimbLedge, true);

            // You can jump off whatever you're hanging
        }
        else if (CharInput.JumpPressed)
        {
            AllowAirJump();

            // You can also just let go
        }
        else if (CharInput.PickupPressed)
        {
            DropHangTarget();
            MecanimAnimator.SetBool(MecanimHashes.Fall, true);
        }
    }
示例#18
0
 protected override void ApplyMovingHorizontal(float elapsedTime)
 {
     base.ApplyMovingHorizontal(elapsedTime);
     MecanimAnimator.SetFloat(MecanimHashes.HorizontalSpeed, Direction.x * HorizontalSpeed / Settings.MaxHorizontalSpeed);
 }
示例#19
0
 protected override void ApplyClimbingVertical(float vertical)
 {
     base.ApplyClimbingVertical(vertical);
     MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);
 }
示例#20
0
 protected override void ApplyGravity(float elapsedTime)
 {
     base.ApplyGravity(elapsedTime);
     MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);
 }
示例#21
0
 public override void StepDown()
 {
     MecanimAnimator.SetFloat(MecanimHashes.XDirection, Direction.x);
     MecanimAnimator.SetBool(MecanimHashes.SteppingDown, true);
 }
示例#22
0
    // ClimbingLadderState = Animator.StringToHash("Climbing.ClimbingLadder");
    // ClimbingRopeState = Animator.StringToHash("Climbing.ClimbingRope");
    protected void ClimbingVertical(float elapsedTime)
    {
        // Make sure we have something to climb on
        if (ActiveHangTarget == null)
        {
            DropHangTarget();
            MecanimAnimator.SetBool(MecanimHashes.Fall, true);
            return;
        }

        // We let go when we touch the floor
        if (IsGrounded && TimeInCurrentState > 0)
        {
            DropHangTarget();
            return;
        }

        // Horizontal motion
        //if(VerticalSpeed != 0 && ActiveHangTarget.DoesFaceZAxis())
        //    ApplyClimbingStrafing( CharInput.Horizontal );
        //else
        HorizontalSpeed = 0;
        SetMecanimAnimatorHorizontalSpeedFloat();

        // Make sure we're facing the correct direction
        if (ActiveHangTarget.DoesFaceZAxis())
        {
            Direction = Vector3.zero;
        }
        else
        {
            bool ladderToRight = ActiveHangTarget.transform.position.x - transform.position.x > 0.0f;
            if (ladderToRight)
            {
                Direction = Vector3.right;
            }
            else
            {
                Direction = Vector3.left;
            }
        }

        // The vertical motion is the most important when climbing
        ApplyClimbingVertical(CharInput.Vertical);
        if (VerticalSpeed == 0)
        {
            if (InputMoveForward)
            {
                VerticalSpeed = Settings.LadderClimbingSpeed;
            }
            else if (InputMoveBackward)
            {
                VerticalSpeed = -Settings.LadderClimbingSpeed;
            }
            MecanimAnimator.SetFloat(MecanimHashes.VerticalSpeed, VerticalSpeed);
            MecanimAnimator.SetBool(MecanimHashes.Fall, false);
        }

        // You can press up/forward on ledges to climb up
        if (ActiveHangTarget is Ledge && (CharInput.Up || InputMoveForward))
        {
            _ledge = ActiveHangTarget as Ledge;
            MecanimAnimator.SetBool(MecanimHashes.ClimbLedge, true);

            // You can let go of what you're climbing with the pickup button
        }
        else if (CharInput.PickupPressed)
        {
            MecanimAnimator.SetBool(MecanimHashes.Fall, true);
            MecanimAnimator.SetBool(MecanimHashes.ClimbRope, false);
            DropHangTarget();
            return;
        }

        // You can jump off ropes and ladders
        AllowAirJump();
    }
示例#23
0
 private void SetMecanimAnimatorHorizontalSpeedFloat()
 {
     MecanimAnimator.SetFloat(MecanimHashes.HorizontalSpeed, Direction.x * HorizontalSpeed / Settings.MaxHorizontalSpeed);
 }