public static void FireBeamWeapon(Entity launchingEntity, Entity targetEntity, double beamVelocity, double beamLenInSeconds) { var ourState = Entity.GetRalitiveState(launchingEntity); var tgtState = Entity.GetRalitiveState(targetEntity); Vector3 leadToTgt = (tgtState.Velocity - ourState.Velocity); Vector3 vectorToTgt = (tgtState.pos = ourState.pos); var distanceToTgt = vectorToTgt.Length(); var timeToTarget = distanceToTgt / beamVelocity; var futureDate = launchingEntity.StarSysDateTime + TimeSpan.FromSeconds(timeToTarget); var futurePosition = Entity.GetAbsoluteFuturePosition(targetEntity, futureDate); var ourAbsPos = Entity.GetAbsoluteFuturePosition(launchingEntity, futureDate); var normVector = Vector3.Normalise(futurePosition - ourAbsPos); var absVector = normVector * beamVelocity; var startPos = (PositionDB)launchingEntity.GetDataBlob <PositionDB>().Clone(); var beamInfo = new BeamInfoDB(launchingEntity.Guid); var beamlenInMeters = beamLenInSeconds * 299792458; beamInfo.Positions = new Vector3[2]; beamInfo.Positions[0] = startPos.AbsolutePosition_m; beamInfo.Positions[1] = startPos.AbsolutePosition_m - normVector * beamlenInMeters; beamInfo.VelocityVector = absVector; List <BaseDataBlob> dataBlobs = new List <BaseDataBlob>(); dataBlobs.Add(beamInfo); //dataBlobs.Add(new ComponentInstancesDB()); dataBlobs.Add(startPos); //dataBlobs.Add(new NameDB("Beam", launchingEntity.FactionOwner, "Beam" )); var newbeam = Entity.Create(launchingEntity.Manager, launchingEntity.FactionOwner, dataBlobs); }
public BeamIcon(Entity entity) : base(entity.GetDataBlob <PositionDB>()) { _beamInfo = entity.GetDataBlob <BeamInfoDB>(); _entity = entity; entity.ChangeEvent += Entity_ChangeEvent; OnPhysicsUpdate(); }
public static void BeamMovePhysics(BeamInfoDB beamInfo, int seconds) { for (int i = 0; i < seconds; i++) { beamInfo.PosDB.AbsolutePosition_m += beamInfo.VelocityVector; for (int j = 0; j < beamInfo.Positions.Length; j++) { beamInfo.Positions[j] += beamInfo.VelocityVector; } } }