/// <summary> /// This returns the average position and speed of the collisions /// </summary> public static Tuple<Point3D, double> GetAverageCollision(MaterialCollision[] collisions, Body body) { if (collisions == null || collisions.Length == 0) { throw new ArgumentException("At least one collision must be passed in"); } double sumX = 0; double sumY = 0; double sumZ = 0; double sumSpeed = 0; foreach (MaterialCollision collision in collisions) { Point3D position; Vector3D normal; double speed; collision.GetContactPositionAndNormalWorld(out position, out normal, out speed, body); sumX += position.X; sumY += position.Y; sumZ += position.Z; sumSpeed += Math.Abs(speed); } Point3D avgPosition = new Point3D(sumX / collisions.Length, sumY / collisions.Length, sumZ / collisions.Length); double avgSpeed = sumSpeed / collisions.Length; return Tuple.Create(avgPosition, avgSpeed); }
public WeaponDamage CalculateDamage(MaterialCollision[] collisions) { if (!_isFullySetUp || collisions.Length == 0) { return null; } double damangeMult = GetDamageMultiplier(); if (Math1D.IsNearZero(damangeMult)) { return null; } var avgCollision = MaterialCollision.GetAverageCollision(collisions, _bot.PhysicsBody); //TODO: See if this position is along the ramming direction double speed = avgCollision.Item2 / 10; // a speed of 10 is considered an average impact speed double damage = speed * damangeMult; WeaponDamage retVal = new WeaponDamage(avgCollision.Item1, damage); // The act of hitting something needs to stop the ram, otherwise, they just keep pushing against the item // and continue to do damage StopRamming(); return retVal; }