private void BeamDamageCheck(GameTime gameTime) { if (turretWeapon.firetype != Weapon.fireType.Beam) { return; } if (!turretWeapon.beamIsFiring()) { return; } if (turretWeapon.curBeamDamageTime > 0) { turretWeapon.curBeamDamageTime -= (int)gameTime.ElapsedGameTime.TotalMilliseconds; return; } int rayLength = turretWeapon.beamRange; turretWeapon.curBeamDamageTime = turretWeapon.beamDamageTime; Matrix turretOrientation = Matrix.CreateFromQuaternion(rotateQuat); //now let's check if the beam damaged any of the ships. for (int k = 0; k < FrameworkCore.level.Ships.Count; k++) { Collideable ship = FrameworkCore.level.Ships[k]; //don't hit myself. if (ship == parentShip) { continue; } //don't hit destroyed ships. if (ship.IsDestroyed) { continue; } //no friendly fire. if (ship.owner != null && ship.owner.factionName == parentShip.owner.factionName) { continue; } for (int i = 0; i < muzzleOffsets.Length; i++) { Vector3 muzzleVec = position; muzzleVec += (turretOrientation.Right * muzzleOffsets[i].X) + (turretOrientation.Up * muzzleOffsets[i].Y) + (turretOrientation.Forward * -muzzleOffsets[i].Z); Vector3 finalPredictedPosition = muzzleVec + turretOrientation.Forward * 128; Vector3 rayDir = finalPredictedPosition - muzzleVec; rayDir.Normalize(); Ray beamRay = new Ray(muzzleVec, rayDir); if (ship.CollisionSpheres.Length > 1) { //if this is a multi-sphere ship, then first do a //preliminary check on the ship's all-encompassing bSphere. //if it comes false, then skip doing the detailed check. if (ship.BSphere.Intersects(beamRay) > rayLength) { continue; } } for (int m = 0; m < ship.CollisionSpheres.Length; m++) { if (ship.CollisionSpheres[m].sphere.Intersects(beamRay) <= rayLength) { ship.beamHit(parentShip, ship.CollisionSpheres[m].sphere.Center, turretWeapon.beamMinDamage, turretWeapon.beamMaxDamage, muzzleVec); break; } } } } }