예제 #1
0
        /// <summary>
        /// Deals damage to the receiver.
        /// </summary>
        /// <param name="receiver">Damage receiving entity.</param>
        public void DealDamage(IDamageReceiver receiver)
        {
            var calculations        = Calculations.GetInstance();
            var receiverKineticData = receiver.GetKineticData();

            float thisKineticEnergy     = calculations.CalcKineticEnergy(_rigidBody.velocity, _rigidBody.mass);
            float receiverKineticEnergy =
                calculations.CalcKineticEnergy(receiverKineticData.Velocity, receiverKineticData.Mass);
            float velocityAngleFactor = VectorManipulator.CalcAngleBetweenVectors(_rigidBody.velocity, receiverKineticData.Velocity);

            //Head on collision means 0°. Perfect amortization means 180°. -cosa describes this relation, we get cosa.
            velocityAngleFactor = -velocityAngleFactor;

            receiverKineticEnergy *= velocityAngleFactor;
            float totalEnergy = thisKineticEnergy + receiverKineticEnergy;

            receiver.ReceiveDamage(totalEnergy);
        }
예제 #2
0
 /// <summary>
 /// Returns kinetic data of the _damageReceiver, like velocity and mass.
 /// </summary>
 /// <returns></returns>
 public KineticObjectData GetKineticData()
 {
     return(_damageReceiver.GetKineticData());
 }