public static bool checkPossibleTarget(ModuleDockingStrut Origin, ModuleDockingStrut Target) { try { float distance = Vector3.Distance(Target.part.transform.position, Origin.part.transform.position); if (distance > Origin.MaxDistance) return false; RaycastHit info = new RaycastHit(); Vector3 start = Origin.rayCastOrigin; Vector3 dir = (Target.strutTarget - start).normalized; bool hit = Physics.Raycast(new Ray(start, dir), out info, Origin.MaxDistance + 1); Part tmpp = DSUtil.PartFromHit(info); if (hit && tmpp == Target.part) hit = false; return !hit; } catch { return false; } }
public static void setPossibleTarget(ModuleDockingStrut Origin, ModuleDockingStrut Target) { float distance = Vector3.Distance(Target.part.transform.position, Origin.part.transform.position); if (distance > Origin.MaxDistance) { Target.SetErrorMessage("Out of range by " + Math.Round(distance - Origin.MaxDistance, 2) + "m"); return; } RaycastHit info = new RaycastHit(); Vector3 start = Origin.rayCastOrigin; Vector3 dir = (Target.strutTarget - start).normalized; bool hit = Physics.Raycast(new Ray(start, dir), out info, Origin.MaxDistance + 1); Part tmpp = PartFromHit(info); if (hit && tmpp == Target.part) hit = false; if (hit) { Target.SetErrorMessage("Obstructed by " + tmpp.name); return; } Target.mode = DSMode.TARGET; Target.TargeterDS = Origin; foreach (BaseEvent e in Target.Events) { e.active = e.guiActive = false; } }
public static bool checkPossibleTarget(ModuleDockingStrut Origin, ModuleDockingStrut Target) { try { float distance = Vector3.Distance(Target.part.transform.position, Origin.part.transform.position); if (distance > Origin.MaxDistance) { return(false); } RaycastHit info = new RaycastHit(); Vector3 start = Origin.rayCastOrigin; Vector3 dir = (Target.strutTarget - start).normalized; bool hit = Physics.Raycast(new Ray(start, dir), out info, Origin.MaxDistance + 1); Part tmpp = DSUtil.PartFromHit(info); if (hit && tmpp == Target.part) { hit = false; } return(!hit); } catch { return(false); } }
public static bool GetDS(this Vessel v, Guid TargetID, out ModuleDockingStrut Target) { foreach (Part p in v.Parts) { if (p.Modules.Contains("ModuleDockingStrut") && (p.Modules["ModuleDockingStrut"] as ModuleDockingStrut).ID == TargetID) { Target = (p.Modules["ModuleDockingStrut"] as ModuleDockingStrut); return true; } } Target = null; return false; }
public static bool GetDS(this Vessel v, Guid TargetID, out ModuleDockingStrut Target) { foreach (Part p in v.Parts) { if (p.Modules.Contains("ModuleDockingStrut") && (p.Modules["ModuleDockingStrut"] as ModuleDockingStrut).ID == TargetID) { Target = (p.Modules["ModuleDockingStrut"] as ModuleDockingStrut); return(true); } } Target = null; return(false); }
public void SetTarget(ModuleDockingStrut PosTarget) { if (!DSUtil.checkPossibleTarget(this, PosTarget)) { mode = DSMode.UNLINKED; Targeted = false; return; } foreach (BaseEvent e in Events) { e.active = e.guiActive = false; } TargetDS = PosTarget; TargetID = TargetDS.ID; Targeted = true; mode = DSMode.LINKED; SetStrutEnd(TargetDS.strutTarget); }
public static void setPossibleTarget(ModuleDockingStrut Origin, ModuleDockingStrut Target) { float distance = Vector3.Distance(Target.part.transform.position, Origin.part.transform.position); if (distance > Origin.MaxDistance) { Target.SetErrorMessage("Out of range by " + Math.Round(distance - Origin.MaxDistance, 2) + "m"); return; } RaycastHit info = new RaycastHit(); Vector3 start = Origin.rayCastOrigin; Vector3 dir = (Target.strutTarget - start).normalized; bool hit = Physics.Raycast(new Ray(start, dir), out info, Origin.MaxDistance + 1); Part tmpp = PartFromHit(info); if (hit && tmpp == Target.part) { hit = false; } if (hit) { Target.SetErrorMessage("Obstructed by " + tmpp.name); return; } Target.mode = DSMode.TARGET; Target.TargeterDS = Origin; foreach (BaseEvent e in Target.Events) { e.active = e.guiActive = false; } }
public void SetTarget(ModuleDockingStrut PosTarget) { if (!DSUtil.checkPossibleTarget(this, PosTarget)) { mode = DSMode.UNLINKED; Targeted = false; return; } foreach (BaseEvent e in Events) e.active = e.guiActive = false; TargetDS = PosTarget; TargetID = TargetDS.ID; Targeted = true; mode = DSMode.LINKED; SetStrutEnd(TargetDS.strutTarget); }