예제 #1
0
        /// <summary>
        /// Applies damage to itself
        /// </summary>
        /// <param name="damage">Damage.</param>
        protected virtual void SelfDamage(int damage)
        {
            if (_health != null)
            {
                _health.Damage(damage, gameObject, 0f, DamageTakenInvincibilityDuration);
            }

            // we apply knockback to ourself
            if (_coreController != null)
            {
                Vector2 totalVelocity  = _colliderCoreController.Speed + _velocity;
                Vector2 knockbackForce = new Vector2(
                    -1 * Mathf.Sign(totalVelocity.x) * DamageTakenKnockbackForce.x,
                    -1 * Mathf.Sign(totalVelocity.y) * DamageTakenKnockbackForce.y);

                if (DamageTakenKnockbackType == KnockbackStyles.SetForce)
                {
                    _coreController.SetForce(knockbackForce);
                }
                if (DamageTakenKnockbackType == KnockbackStyles.AddForce)
                {
                    _coreController.AddForce(knockbackForce);
                }
            }
        }
예제 #2
0
        /// <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
            _colliderCoreController = health.gameObject.GetComponentNoAlloc <CoreController>();

            if ((_colliderCoreController != null) && (DamageCausedKnockbackForce != Vector2.zero) && (!_colliderHealth.Invulnerable) && (!_colliderHealth.ImmuneToKnockback))
            {
                _knockbackForce.x = DamageCausedKnockbackForce.x;
                if (DamageCausedKnockbackDirection == KnockbackDirections.BasedOnSpeed)
                {
                    Vector2 totalVelocity = _colliderCoreController.Speed + _velocity;
                    _knockbackForce.x *= -1 * Mathf.Sign(totalVelocity.x);
                }
                if (DamagedTakenKnockbackDirection == KnockbackDirections.BasedOnOwnerPosition)
                {
                    if (Owner == null)
                    {
                        Owner = this.gameObject;
                    }
                    Vector2 relativePosition = _colliderCoreController.transform.position - Owner.transform.position;
                    _knockbackForce.x *= Mathf.Sign(relativePosition.x);
                }

                _knockbackForce.y = DamageCausedKnockbackForce.y;

                if (DamageCausedKnockbackType == KnockbackStyles.SetForce)
                {
                    _colliderCoreController.SetForce(_knockbackForce);
                }
                if (DamageCausedKnockbackType == KnockbackStyles.AddForce)
                {
                    _colliderCoreController.AddForce(_knockbackForce);
                }
            }

            /*if (FreezeFramesOnHitDuration > 0)
             * {
             *  MMEventManager.TriggerEvent(new MMFreezeFrameEvent(FreezeFramesOnHitDuration));
             * }*/

            // we apply the damage to the thing we've collided with
            _colliderHealth.Damage(DamageCaused, gameObject, InvincibilityDuration, InvincibilityDuration);
            SelfDamage(DamageTakenEveryTime + DamageTakenDamageable);
        }