/// <summary> /// Describes what happens when colliding with a damageable object /// </summary> /// <param name="health">Health.</param> protected virtual void OnCollideWithDamageable(Health health) { // if what we're colliding with is a CorgiController, we apply a knockback force _colliderCorgiController = health.gameObject.MMGetComponentNoAlloc <CorgiController>(); ApplyDamageCausedKnockback(); OnHitDamageable?.Invoke(); HitDamageableFeedback?.PlayFeedbacks(this.transform.position); if ((FreezeFramesOnHitDuration > 0) && (Time.timeScale > 0)) { MMFreezeFrameEvent.Trigger(Mathf.Abs(FreezeFramesOnHitDuration)); } // we apply the damage to the thing we've collided with _colliderHealth.Damage(DamageCaused, gameObject, InvincibilityDuration, InvincibilityDuration); if (_colliderHealth.CurrentHealth <= 0) { OnKill?.Invoke(); } SelfDamage(DamageTakenEveryTime + DamageTakenDamageable); }
/// <summary> /// Describes what happens when colliding with a damageable object /// </summary> /// <param name="health">Health.</param> protected virtual void OnCollideWithDamageable(Health health) { // if what we're colliding with is a CorgiController, we apply a knockback force _colliderCorgiController = health.gameObject.MMGetComponentNoAlloc <CorgiController>(); if ((_colliderCorgiController != null) && (DamageCausedKnockbackForce != Vector2.zero) && (!_colliderHealth.TemporaryInvulnerable) && (!_colliderHealth.Invulnerable) && (!_colliderHealth.ImmuneToKnockback)) { _knockbackForce.x = DamageCausedKnockbackForce.x; if (DamageCausedKnockbackDirection == KnockbackDirections.BasedOnSpeed) { Vector2 totalVelocity = _colliderCorgiController.Speed + _velocity; _knockbackForce.x *= -1 * Mathf.Sign(totalVelocity.x); } if (DamagedTakenKnockbackDirection == KnockbackDirections.BasedOnOwnerPosition) { if (Owner == null) { Owner = this.gameObject; } Vector2 relativePosition = _colliderCorgiController.transform.position - Owner.transform.position; _knockbackForce.x *= Mathf.Sign(relativePosition.x); } _knockbackForce.y = DamageCausedKnockbackForce.y; if (DamageCausedKnockbackType == KnockbackStyles.SetForce) { _colliderCorgiController.SetForce(_knockbackForce); } if (DamageCausedKnockbackType == KnockbackStyles.AddForce) { _colliderCorgiController.AddForce(_knockbackForce); } } HitDamageableFeedback?.PlayFeedbacks(this.transform.position); if ((FreezeFramesOnHitDuration > 0) && (Time.timeScale > 0)) { MMFreezeFrameEvent.Trigger(Mathf.Abs(FreezeFramesOnHitDuration)); } // we apply the damage to the thing we've collided with _colliderHealth.Damage(DamageCaused, gameObject, InvincibilityDuration, InvincibilityDuration); SelfDamage(DamageTakenEveryTime + DamageTakenDamageable); }
protected void FreezeGame() { MMFreezeFrameEvent.Trigger(FreezeTime); }