Пример #1
0
 /// <summary>
 /// When the weapon is used, plays the corresponding sound
 /// </summary>
 public virtual void WeaponUse()
 {
     // apply recoil
     if ((RecoilForce > 0f) && (_controller != null))
     {
         if (Owner != null)
         {
             if (Owner.Orientation2D != null)
             {
                 if (Flipped)
                 {
                     _controller.Impact(this.transform.right, RecoilForce);
                 }
                 else
                 {
                     _controller.Impact(-this.transform.right, RecoilForce);
                 }
             }
             else
             {
                 _controller.Impact(-this.transform.forward, RecoilForce);
             }
         }
     }
     TriggerWeaponUsedFeedback();
 }
Пример #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 TopDownController, we apply a knockback force
            _colliderTopDownController = health.gameObject.MMGetComponentNoAlloc <TopDownController>();
            _colliderRigidBody         = health.gameObject.MMGetComponentNoAlloc <Rigidbody>();

            if ((_colliderTopDownController != null) && (DamageCausedKnockbackForce != Vector3.zero) && (!_colliderHealth.Invulnerable) && (!_colliderHealth.ImmuneToKnockback))
            {
                _knockbackForce.x = DamageCausedKnockbackForce.x;
                _knockbackForce.y = DamageCausedKnockbackForce.y;

                if (DamageCausedKnockbackDirection == KnockbackDirections.BasedOnSpeed)
                {
                    Vector3 totalVelocity = _colliderTopDownController.Speed + _velocity;
                    _knockbackForce = Vector3.RotateTowards(DamageCausedKnockbackForce, totalVelocity.normalized, 10f, 0f);
                }
                if (DamagedTakenKnockbackDirection == KnockbackDirections.BasedOnOwnerPosition)
                {
                    if (Owner == null)
                    {
                        Owner = this.gameObject;
                    }
                    Vector3 relativePosition = _colliderTopDownController.transform.position - Owner.transform.position;
                    _knockbackForce = Vector3.RotateTowards(DamageCausedKnockbackForce, relativePosition.normalized, 10f, 0f);
                }

                if (DamageCausedKnockbackType == KnockbackStyles.AddForce)
                {
                    _colliderTopDownController.Impact(_knockbackForce.normalized, _knockbackForce.magnitude);
                }
            }

            HitDamageableFeedback?.PlayFeedbacks(this.transform.position);

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