private void animPrepareToSlam() { switch (attackAnimationState) { case AttackAnimationState.NeedsToStart: Vector2 launchForce = new Vector2(0f, 300f); originalBasketball.localPosition = new Vector2(0.18f, 0.21f); GetComponent <BoxCollider2D>().enabled = false; rigidbody2D.AddForce(launchForce); anim.SetTrigger("Dunking"); attackAnimationState = AttackAnimationState.InProgress; break; case AttackAnimationState.InProgress: if (rigidbody2D.velocity.magnitude < 0.8) { anim.SetTrigger("Slamming"); rigidbody2D.gravityScale = 0; originalBasketball.renderer.enabled = false; attacksketball.position = transform.position + new Vector3(0.18f, 0.21f, 0.0f); basketballVelocity = currentAttackTarget.transform.position - attacksketball.position; basketballVelocity *= 2; attacksketball.renderer.enabled = true; playSound(throwSound); attackAnimationState = AttackAnimationState.Complete; } break; case AttackAnimationState.Complete: attacksketball.position = attacksketball.position + basketballVelocity * Time.fixedDeltaTime; if (attacksketball.position.x > (currentAttackTarget.transform.position.x - 0.1)) { attacksketball.renderer.enabled = false; currentAttackTarget.Damage(currentAttack.Power); playSound(hitSound); currentAnimation = AnimationSequence.ReturningFromSlamming; attackAnimationState = AttackAnimationState.NeedsToStart; } break; } }
private void animFlyTowardsTarget() { switch (attackAnimationState) { case AttackAnimationState.NeedsToStart: initialPosition = transform.position; GetComponent <JamesGasBehavior>().EnableFlightMode(); attackAnimationState = AttackAnimationState.InProgress; break; case AttackAnimationState.InProgress: rigidbody2D.AddForce(new Vector2(0, 400) * Time.fixedDeltaTime); if (transform.position.y > 0.1f) { playSound(GasBlastSound); attackAnimationState = AttackAnimationState.Complete; } break; case AttackAnimationState.Complete: rigidbody2D.AddForce(currentAttackTarget.transform.position - transform.position * 250 * Time.fixedDeltaTime); if (transform.rotation.eulerAngles.z < 170 && transform.rotation.eulerAngles.z > 163) { currentAttackTarget.Damage(currentAttack.Power); currentAnimation = AnimationSequence.FlyingBack; attackAnimationState = AttackAnimationState.NeedsToStart; } break; } }
private void animJumpForward() { switch (attackAnimationState) { case AttackAnimationState.NeedsToStart: Vector2 launchVelocity = new Vector2(7f, 0f); setDragEnabled(false); //calculate the needed initial vertical speed to reach the target float dist = currentAttackTarget.transform.position.x - transform.position.x - 0.3f; float time = dist / launchVelocity.x; launchVelocity.y = Mathf.Abs(Physics2D.gravity.y) / 2 * time; // cheap hack to hit floating bosses if (currentAttackTarget.transform.position.y > transform.position.y + 0.2) { launchVelocity.y += 4f; } rigidbody2D.velocity = launchVelocity; attackAnimationState = AttackAnimationState.InProgress; GetComponent <Animator> ().SetBool("IsAttacking", true); break; case AttackAnimationState.InProgress: if (transform.position.x > currentAttackTarget.transform.position.x - 1f) { playSound(knifeSlash); currentAttackTarget.Damage(currentAttack.Power); attackAnimationState = AttackAnimationState.Complete; } break; case AttackAnimationState.Complete: if (rigidbody2D.velocity == Vector2.zero) { currentAnimation = AnimationSequence.JumpBackward; attackAnimationState = AttackAnimationState.NeedsToStart; } break; } }