public override void Update() { base.Update(); if (!isAlive) { return; } isAttackingAnim = baseAnim.GetCurrentAnimatorStateInfo(0).IsName("attack1") || baseAnim.GetCurrentAnimatorStateInfo(0).IsName("attack2") || baseAnim.GetCurrentAnimatorStateInfo(0).IsName("attack3") || baseAnim.GetCurrentAnimatorStateInfo(0).IsName("jump_attack") || baseAnim.GetCurrentAnimatorStateInfo(0).IsName("run_attack"); isJumpLandAnim = baseAnim.GetCurrentAnimatorStateInfo(0).IsName("jump_land"); isJumpingAnim = baseAnim.GetCurrentAnimatorStateInfo(0).IsName("jump_rise") || baseAnim.GetCurrentAnimatorStateInfo(0).IsName("jump_fall"); isHurtAnim = baseAnim.GetCurrentAnimatorStateInfo(0).IsName("hurt"); isPickingUpAnim = baseAnim.GetCurrentAnimatorStateInfo(0).IsName("pickup"); if (isAutoPiloting) { return; } float h = input.GetHorizontalAxis(); float v = input.GetVerticalAxis(); bool jump = input.GetJumpButtonDown(); bool attack = input.GetAttackButtonDown(); currentDir = new Vector3(h, 0, v); currentDir.Normalize(); if (!isAttackingAnim) { if (chainComboTimer > 0) { chainComboTimer -= Time.deltaTime; if (chainComboTimer < 0) { chainComboTimer = 0; currentAttackChain = 0; evaluatedAttackChain = 0; baseAnim.SetInteger("CurrentChain", currentAttackChain); baseAnim.SetInteger("EvaluatedChain", evaluatedAttackChain); } } if (v == 0 && h == 0) { Stop(); isMoving = false; } else if (!isMoving && (v != 0 || h != 0)) { isMoving = true; float dotProduct = Vector3.Dot(currentDir, lastWalkVector); if (canRun && Time.time < lastWalk + tapAgainToRunTime && dotProduct > 0) { Run(); } else { Walk(); if (h != 0) { lastWalkVector = currentDir; lastWalk = Time.time; } } } } if (jump && hasWeapon) { weaponDropPressed = true; DropWeapon(); } if (weaponDropPressed && !jump) { weaponDropPressed = false; } if (canJump && jump && !isKnockedOut && !isJumpLandAnim && !isAttackingAnim && !isPickingUpAnim && !weaponDropPressed && (isGrounded || (isJumpingAnim && Time.time < lastJumpTime + jumpDuration))) { Jump(currentDir); } if (attack && Time.time >= lastAttackTime + attackLimit && isGrounded && !isPickingUpAnim) { if (nearbyPowerup != null && nearbyPowerup.CanEquip()) { lastAttackTime = Time.time; Stop(); PickupWeapon(nearbyPowerup); } } if (attack && Time.time >= lastAttackTime + attackLimit && !isKnockedOut && !isPickingUpAnim) { lastAttackTime = Time.time; Attack(); } if (hurtTolerance < hurtLimit) { hurtTolerance += Time.deltaTime * recoveryRate; hurtTolerance = Mathf.Clamp(hurtTolerance, 0, hurtLimit); } }
public override void Update() { //calls superclass base.Update(); //handles button presses after death if (!isAlive) { return; } //updates animation variable that stores whether hero is attacking or not isAttackingAnim = baseAnim.GetCurrentAnimatorStateInfo(0).IsName("attack1") || baseAnim.GetCurrentAnimatorStateInfo(0).IsName("attack2") || baseAnim.GetCurrentAnimatorStateInfo(0).IsName("attack3") || baseAnim.GetCurrentAnimatorStateInfo(0).IsName("jump_attack") || baseAnim.GetCurrentAnimatorStateInfo(0).IsName("run_attack"); //These lines update the variables that store whether the hero is jumping or not. isJumpLandAnim = baseAnim.GetCurrentAnimatorStateInfo(0).IsName("jump_land"); isJumpingAnim = baseAnim.GetCurrentAnimatorStateInfo(0).IsName("jump_rise") || baseAnim.GetCurrentAnimatorStateInfo(0).IsName("jump_fall"); //tracks when the hurt animation is played isHurtAnim = baseAnim.GetCurrentAnimatorStateInfo(0).IsName("hurt"); //tracks when pickup animation is played isPickingUpAnim = baseAnim.GetCurrentAnimatorStateInfo(0).IsName("pickup"); //prevents from performing actions during entrance if (isAutoPiloting) { return; } float h = input.GetHorizontalAxis(); float v = input.GetVerticalAxis(); bool jump = input.GetJumpButtonDown(); bool attack = input.GetAttackButtonDown(); curDirection = new Vector3(h, 0, v); curDirection.Normalize(); if (!isAttackingAnim) { if (chainComboTimer > 0) { chainComboTimer -= Time.deltaTime; if (chainComboTimer < 0) { chainComboTimer = 0; currentAttackChain = 0; evaluatedAttackChain = 0; baseAnim.SetInteger("CurrentChain", currentAttackChain); baseAnim.SetInteger("EvaluatedChain", evaluatedAttackChain); } } if (v == 0 && h == 0) { Stop(); isMoving = false; } else if (!isMoving && (v != 0 || h != 0)) { isMoving = true; float dotProduct = Vector3.Dot(curDirection, lastWalkVector); if (canRun && Time.time < lastWalk + tapAgainToRunTime && dotProduct > 0) { Run(); } else { Walk(); if (h != 0) { lastWalkVector = curDirection; lastWalk = Time.time; } } } } if (jump && hasWeapon) { weaponDropPressed = true; DropWeapon(); } if (weaponDropPressed && !jump) { weaponDropPressed = false; } //triggers/calls Jump if (canJump && jump && !isKnockedOut && jumpCollider.CanJump(curDirection, frontVector) && !isJumpLandAnim && !isAttackingAnim && !isPickingUpAnim && !weaponDropPressed && (isGrounded || (isJumpingAnim && Time.time < lastJumpTime + jumpDuration))) { Jump(curDirection); } //pickups have priority over attacking if (attack && Time.time >= lastAttackTime + attackLimit && isGrounded && !isPickingUpAnim) { if (nearbyPowerup != null && nearbyPowerup.CanEquip()) { lastAttackTime = Time.time; Stop(); PickupWeapon(nearbyPowerup); } } //triggers/calls Attack if (attack && Time.time >= lastAttackTime + attackLimit && !isKnockedOut && !isPickingUpAnim) { lastAttackTime = Time.time; Attack(); } //calculates knockdown tolerance if (hurtTolerance < hurtLimit) { hurtTolerance += Time.deltaTime * recoveryRate; hurtTolerance = Mathf.Clamp(hurtTolerance, 0, hurtLimit); } }