void Update() { Debug.DrawLine(Vector3.zero, myTransform.forward); ApplyGravity(); PerformActionInProgress(); UpdateLockOn(); controller.Think(); TryDebugs(); // Animation sector if (!isAttacking && (IsIdle() || IsMoving()) && !chargeUpTimer.IsRunning()) { if (isBlocking) { animation.CrossFade(blockIdle.name, 0.1f); } else { animation.Play(idle.name, PlayMode.StopAll); } } else if (IsDodging()) { animation.Play(idle.name, PlayMode.StopAll); } else if (IsInMoveReaction()) { // Interrupt or stop attack animation animation.Play(idle.name, PlayMode.StopAll); } // Color and effects RenderColor(); if (chargeUpTimer.IsRunning()) { float chargeUpRatio = chargeUpTimer.GetTimerRuntime() / currentAttack.chargeAnimation.length; DisplayChargeEffects(chargeUpRatio); } else { HideChargeEffects(); } }
/* * Resolve a hit and perform the appropriate reaction. This may mean * taking damage or it may mean resolving a block. */ public void ApplyDamage(Damage incomingDamage) { //TODO derive this from the attack, or damage info playerCamera.Shake(3.0f, 0.2f, 0.4f); // Handle blocked hits first Vector3 toHit = incomingDamage.HitLocation.point - myTransform.position; bool hitFromFront = Vector3.Dot(myTransform.forward, toHit.normalized) < 0; if (isBlocking && !hitFromFront) { // Uncomment these to help debug this, but it should be correct. //Debug.DrawLine (Vector3.zero, myTransform.forward); //Debug.DrawLine (Vector3.zero, toHit.normalized, Color.red); //Debug.DrawLine (myTransform.forward, toHit.normalized, Color.green); shieldFlash.Flash(); PlaySound(blockSound); // Cause attacker to get knocked back // TODO We need a check for if the damage is ranged if (shieldTime.GetTimerRuntime() < superBlockWindow) { // Only knockback enemies if non-projectile attacks if (!incomingDamage.Attack.IsRanged()) { Enemy attackingEnemy = incomingDamage.Attacker.GetComponent <Enemy> (); attackingEnemy.ReceiveKnockback(toHit.normalized * 15.0f, 0.5f); } } DecreaseShieldDurability(incomingDamage); } else { // Play a new hit sound at the location. Must make minDistance the same as the // attack channel so that it plays at the same volume. This is kind of weird... AudioSource source = SoundManager.PlayClipAtPoint(takeHitSound, incomingDamage.HitLocation.point); source.minDistance = attackAndBlockChannel.minDistance; lastHitTime = Time.time; health.TakeDamage(incomingDamage); // Handle reaction type of successful hits if (incomingDamage.Attack == null) { // TODO This should be resolved when we have Damage refactored to either // always include Attack or not. Right now we get attack on only some damage // instances } else if (incomingDamage.Attack.reactionType == AttackData.ReactionType.Knockback) { // float knockBackDuration = 0.2f; // Knock back in the opposite direction of the attacker. //ReceiveKnockback ((myTransform.position - incomingDamage.Attacker.position).normalized, knockBackDuration); } } }