Example #1
0
    //physics update
    void FixedUpdate()
    {
        //check if we are on the ground
        isGrounded = IsGrounded();

        if (animator)
        {
            //set grounded
            animator.SetAnimatorBool("isGrounded", isGrounded);

            //check if we're falling
            animator.SetAnimatorBool("Falling", !isGrounded && rb.velocity.y < 0.1f && playerState.currentState != UNITSTATE.KNOCKDOWN);

            //update animator direction
            animator.currentDirection = currentDirection;
        }

        //check if the player is inside the camera view area
        playerInCameraView = PlayerInsideCamViewArea();

        //update movement velocity
        if (updateVelocity && MovementStates.Contains(playerState.currentState))
        {
            rb.velocity    = fixedVelocity;
            updateVelocity = false;
        }
    }
Example #2
0
    void FixedUpdate()
    {
        if (!MovementStates.Contains(playerState.currentState) || isDead)
        {
            return;
        }

        //defend
        if (playerState.currentState == UNITSTATE.DEFEND)
        {
            TurnToCurrentDirection();
            return;
        }

        //start a jump
        if (JumpNextFixedUpdate)
        {
            Jump();
            return;
        }

        //land after a jump
        if (jumpInProgress && IsGrounded())
        {
            HasLanded();
            return;
        }

        //A short recovery time after landing
        if (playerState.currentState == UNITSTATE.LAND && Time.time - landTime > landRecoveryTime)
        {
            playerState.SetState(UNITSTATE.IDLE);
        }

        //air and ground Movement
        bool isGrounded = IsGrounded();

        animator.SetAnimatorBool("isGrounded", isGrounded);
        if (isGrounded)
        {
            animator.SetAnimatorBool("Falling", false);
        }

        if (isGrounded)
        {
            MoveGrounded();
        }
        else
        {
            MoveAirborne();
        }

        //always turn towards the current direction
        TurnToCurrentDirection();
    }
Example #3
0
 /// <summary>
 /// set defence on/off
 /// </summary>
 /// <param name="defend"></param>
 private void Defend(bool defend)
 {
     animator.SetAnimatorBool("Defend", defend);
     if (defend)
     {
         //keep turn direction while defending
         if (!canTurnWhileDefending)
         {
             int rot = Mathf.RoundToInt(transform.rotation.eulerAngles.y);
             if (rot >= 180 && rot <= 270)
             {
                 currentDirection = DIRECTION.Left;
             }
             else
             {
                 currentDirection = DIRECTION.Right;
             }
             playerMovement.currentDirection = currentDirection;
         }
         TurnToDir(currentDirection);
         SetVelocity(Vector3.zero);
         playerState.SetState(UNITSTATE.DEFEND);
     }
     else if (playerState.currentState == UNITSTATE.DEFEND)
     {
         playerState.SetState(UNITSTATE.IDLE);
     }
 }
Example #4
0
    void FixedUpdate()
    {
        isGrounded = IsGrounded();

        if (animator)
        {
            animator.SetAnimatorBool("isGrounded", isGrounded);
            animator.SetAnimatorBool("Falling", !isGrounded && rb.velocity.y < 0.1f);
            animator.currentDirection = currentDirection;
        }

        if (updateVelocity && MovementStates.Contains(playerState.currentState))
        {
            rb.velocity    = fixedVelocity;
            updateVelocity = false;
        }
    }
Example #5
0
    //jump kick in progress
    IEnumerator JumpKickInProgress()
    {
        animator.SetAnimatorBool("JumpKickActive", true);

        //a list of enemies that we have hit
        List <GameObject> enemieshit = new List <GameObject>();

        //small delay so the animation has time to play
        yield return(new WaitForSeconds(.1f));

        //check for hit
        while (playerState.currentState == UNITSTATE.JUMPKICK)
        {
            //draw a hitbox in front of the character to see which objects it collides with
            Vector3    boxPosition  = transform.position + (Vector3.up * lastAttack.collHeight) + Vector3.right * ((int)currentDirection * lastAttack.collDistance);
            Vector3    boxSize      = new Vector3(lastAttack.CollSize / 2, lastAttack.CollSize / 2, hitZRange / 2);
            Collider[] hitColliders = Physics.OverlapBox(boxPosition, boxSize, Quaternion.identity, HitLayerMask);

            //hit an enemy only once by adding it to the list of enemieshit
            foreach (Collider col in hitColliders)
            {
                if (!enemieshit.Contains(col.gameObject))
                {
                    enemieshit.Add(col.gameObject);

                    //hit a damagable object
                    IDamagable <DamageObject> damagableObject = col.GetComponent(typeof(IDamagable <DamageObject>)) as IDamagable <DamageObject>;
                    if (damagableObject != null)
                    {
                        damagableObject.Hit(lastAttack);

                        //camera Shake
                        CamShake camShake = Camera.main.GetComponent <CamShake> ();
                        if (camShake != null)
                        {
                            camShake.Shake(.1f);
                        }
                    }
                }
            }
            yield return(null);
        }
    }
Example #6
0
    //combat input event
    private void OnInputEvent(string action, BUTTONSTATE buttonState)
    {
        if (AttackStates.Contains(playerState.currentState) && !isDead)
        {
            //running punch
            if (action == "Punch" && buttonState == BUTTONSTATE.PRESS && playerState.currentState == UNITSTATE.RUN && isGrounded)
            {
                animator.SetAnimatorBool("Run", false);
                if (RunningPunch.animTrigger.Length > 0)
                {
                    doAttack(RunningPunch, UNITSTATE.ATTACK, "Punch");
                }
                return;
            }

            //running kick
            if (action == "Kick" && buttonState == BUTTONSTATE.PRESS && playerState.currentState == UNITSTATE.RUN && isGrounded)
            {
                animator.SetAnimatorBool("Run", false);
                if (RunningKick.animTrigger.Length > 0)
                {
                    doAttack(RunningKick, UNITSTATE.ATTACK, "Kick");
                }
                return;
            }

            //pick up an item
            if (action == "Punch" && buttonState == BUTTONSTATE.PRESS && itemInRange != null && isGrounded && currentWeapon == null)
            {
                interactWithItem();
                return;
            }

            //use an weapon
            if (action == "Punch" && buttonState == BUTTONSTATE.PRESS && isGrounded && currentWeapon != null)
            {
                useCurrentWeapon();
                return;
            }

            //ground punch
            if (action == "Punch" && buttonState == BUTTONSTATE.PRESS && (playerState.currentState != UNITSTATE.PUNCH && NearbyEnemyDown()) && isGrounded)
            {
                if (GroundPunchData.animTrigger.Length > 0)
                {
                    doAttack(GroundPunchData, UNITSTATE.GROUNDPUNCH, "Punch");
                }
                return;
            }

            //ground kick
            if (action == "Kick" && buttonState == BUTTONSTATE.PRESS && (playerState.currentState != UNITSTATE.KICK && NearbyEnemyDown()) && isGrounded)
            {
                if (GroundKickData.animTrigger.Length > 0)
                {
                    doAttack(GroundKickData, UNITSTATE.GROUNDKICK, "Kick");
                }
                return;
            }

            //reset combo when switching to another combo chain (user setting)
            if (resetComboChainOnChangeCombo && (action != lastAttackInput))
            {
                attackNum = -1;
            }

            //default punch
            if (action == "Punch" && buttonState == BUTTONSTATE.PRESS && playerState.currentState != UNITSTATE.PUNCH && playerState.currentState != UNITSTATE.KICK && isGrounded)
            {
                //continue to the next attack if the time is inside the combo window
                bool insideComboWindow = (lastAttack != null && (Time.time < (lastAttackTime + lastAttack.duration + lastAttack.comboResetTime)));
                if (insideComboWindow && !continuePunchCombo && (attackNum < PunchCombo.Length - 1))
                {
                    attackNum += 1;
                }
                else
                {
                    attackNum = 0;
                }

                if (PunchCombo[attackNum] != null && PunchCombo[attackNum].animTrigger.Length > 0)
                {
                    doAttack(PunchCombo[attackNum], UNITSTATE.PUNCH, "Punch");
                }
                return;
            }

            //advance the punch combo if "punch" was pressed during a punch attack
            if (action == "Punch" && buttonState == BUTTONSTATE.PRESS && (playerState.currentState == UNITSTATE.PUNCH) && !continuePunchCombo && isGrounded)
            {
                if (attackNum < PunchCombo.Length - 1)
                {
                    continuePunchCombo = true;
                    continueKickCombo  = false;
                    return;
                }
            }

            //jump punch
            if (action == "Punch" && buttonState == BUTTONSTATE.PRESS && !isGrounded)
            {
                if (JumpKickData.animTrigger.Length > 0)
                {
                    doAttack(JumpKickData, UNITSTATE.JUMPKICK, "Kick");
                    StartCoroutine(JumpKickInProgress());
                }
                return;
            }

            //jump kick
            if (action == "Kick" && buttonState == BUTTONSTATE.PRESS && !isGrounded)
            {
                if (JumpKickData.animTrigger.Length > 0)
                {
                    doAttack(JumpKickData, UNITSTATE.JUMPKICK, "Kick");
                    StartCoroutine(JumpKickInProgress());
                }
                return;
            }

            //default kick
            if (action == "Kick" && buttonState == BUTTONSTATE.PRESS && playerState.currentState != UNITSTATE.KICK && playerState.currentState != UNITSTATE.PUNCH && isGrounded)
            {
                //continue to the next attack if the time is inside the combo window
                bool insideComboWindow = (lastAttack != null && (Time.time < (lastAttackTime + lastAttack.duration + lastAttack.comboResetTime)));
                if (insideComboWindow && !continueKickCombo && (attackNum < KickCombo.Length - 1))
                {
                    attackNum += 1;
                }
                else
                {
                    attackNum = 0;
                }

                doAttack(KickCombo[attackNum], UNITSTATE.KICK, "Kick");
                return;
            }

            //advance the kick combo if "kick" was pressed during a kick attack
            if (action == "Kick" && buttonState == BUTTONSTATE.PRESS && (playerState.currentState == UNITSTATE.KICK) && !continueKickCombo && isGrounded)
            {
                if (attackNum < KickCombo.Length - 1)
                {
                    continueKickCombo  = true;
                    continuePunchCombo = false;
                    return;
                }
            }
        }
    }