//jump IEnumerator doJump() { //set jump state jumpInProgress = true; playerState.SetState(UNITSTATE.JUMPING); //play animation animator.SetAnimatorBool("JumpInProgress", true); animator.SetAnimatorTrigger("JumpUp"); animator.ShowDustEffectJump(); //play sfx if (jumpUpVoice != "") { GlobalAudioPlayer.PlaySFXAtPosition(jumpUpVoice, transform.position); } //set state yield return(new WaitForFixedUpdate()); //start jump while (isGrounded) { SetVelocity(Vector3.up * JumpForce); yield return(new WaitForFixedUpdate()); } //continue until we hit the ground while (!isGrounded) { yield return(new WaitForFixedUpdate()); } //land playerState.SetState(UNITSTATE.LAND); SetVelocity(Vector3.zero); animator.SetAnimatorFloat("MovementSpeed", 0f); animator.SetAnimatorBool("JumpInProgress", false); animator.SetAnimatorBool("JumpKickActive", false); animator.SetAnimatorBool("JumpPunchActive", false); //LETHAL FORCES - Adding Jump Punch animator.ShowDustEffectLand(); //sfx GlobalAudioPlayer.PlaySFX("FootStep"); if (jumpLandVoice != "") { GlobalAudioPlayer.PlaySFXAtPosition(jumpLandVoice, transform.position); } jumpInProgress = false; if (playerState.currentState == UNITSTATE.LAND) { yield return(new WaitForSeconds(landRecoveryTime)); setPlayerState(UNITSTATE.IDLE); } }
//knockDown sequence public IEnumerator KnockDownSequence(GameObject inflictor) { playerState.SetState(UNITSTATE.KNOCKDOWN); animator.StopAllCoroutines(); yield return(new WaitForFixedUpdate()); //look towards the direction of the incoming attack int dir = inflictor.transform.position.x > transform.position.x ? 1 : -1; currentDirection = (DIRECTION_P2)dir; TurnToDir(currentDirection); //update playermovement var pm = GetComponent <PlayerMovement_P2>(); if (pm != null) { pm.CancelJump(); pm.SetDirection(currentDirection); } //add knockback force animator.SetAnimatorTrigger("KnockDown_Up"); while (IsGrounded()) { SetVelocity(new Vector3(KnockbackForce * -dir, KnockdownUpForce, 0)); yield return(new WaitForFixedUpdate()); } //going up... while (rb.velocity.y >= 0) { yield return(new WaitForFixedUpdate()); } //going down animator.SetAnimatorTrigger("KnockDown_Down"); while (!IsGrounded()) { yield return(new WaitForFixedUpdate()); } //hit ground animator.SetAnimatorTrigger("KnockDown_End"); CamShake camShake = Camera.main.GetComponent <CamShake>(); if (camShake != null) { camShake.Shake(.3f); } animator.ShowDustEffectLand(); //sfx GlobalAudioPlayer.PlaySFXAtPosition("Drop", transform.position); //ground slide float t = 0; float speed = 2; Vector3 fromVelocity = rb.velocity; while (t < 1) { SetVelocity(Vector3.Lerp(new Vector3(fromVelocity.x, rb.velocity.y + Physics.gravity.y * Time.fixedDeltaTime, fromVelocity.z), new Vector3(0, rb.velocity.y, 0), t)); t += Time.deltaTime * speed; yield return(null); } //knockDown Timeout SetVelocity(Vector3.zero); yield return(new WaitForSeconds(KnockdownTimeout)); //stand up animator.SetAnimatorTrigger("StandUp"); playerState.currentState = UNITSTATE.STANDUP; yield return(new WaitForSeconds(KnockdownStandUpTime)); playerState.currentState = UNITSTATE.IDLE; }