public void StartMove(Vessel v) { if (!v) { Debug.Log("[Spawn OrX ODST] SpawnVessel tried to move a null vessel "); } if (v.packed) { return; } if (!_placingVessels.Contains(v)) { Debug.Log("[Spawn OrX ODST] SpawnVessel trying to set altitude for " + v.vesselName); MovingVessel = v; IsMovingVessel = true; _up = (v.transform.position - v.mainBody.transform.position).normalized; _startingUp = _up; _vBounds = new VesselBounds(MovingVessel); _moving = true; MoveHeight = _vBounds.BottomLength + 0.5f; _startRotation = MovingVessel.transform.rotation; _currRotation = _startRotation; } }
private void initLR(Vessel v, VesselBounds vbounds) { LineRenderer Lr0; Lr0 = new GameObject().AddComponent <LineRenderer> (); Lr0.material = new Material(Shader.Find("KSP/Emissive/Diffuse")); Lr0.useWorldSpace = true; Lr0.material.SetColor("_EmissiveColor", Color.green); /*Lr0.startWidth = 0.15f; * Lr0.endWidth = 0.15f; * Lr0.positionCount = 4;*/ Lr0.enabled = true; LineRenderer Lr1; Lr1 = new GameObject().AddComponent <LineRenderer> (); Lr1.material = new Material(Shader.Find("KSP/Emissive/Diffuse")); Lr1.useWorldSpace = true; Lr1.material.SetColor("_EmissiveColor", Color.green); /*Lr1.startWidth = 0.15f; * Lr1.endWidth = 0.15f; * Lr1.positionCount = 4;*/ Lr1.enabled = true; renderer0 [v.id] = Lr0; renderer1 [v.id] = Lr1; updateLR(v, vbounds); }
private IEnumerator EndMoveRoutine(VesselBounds vesselBounds) { Vessel v = vesselBounds.vessel; if (!v) { yield break; } yield return(new WaitForFixedUpdate()); vesselBounds.UpdateBounds(); yield return(new WaitForFixedUpdate()); while (_moveMode != MoveModes.Normal) { ToggleMoveMode(); } _moving = false; MoveHeight = 0; _placingVessels.Add(vesselBounds.vessel); float bottomLength = _vBounds.BottomLength; //float heightOffset = GetRadarAltitude(movingVessel) - moveHeight; float altitude = GetRaycastAltitude(vesselBounds); while (v && !v.LandedOrSplashed) { v.IgnoreGForces(240); MovingVessel.IgnoreGForces(240); _up = (v.transform.position - FlightGlobals.currentMainBody.transform.position).normalized; float placeSpeed = Mathf.Clamp(((altitude - bottomLength) * 2), 0.1f, maxPlacementSpeed); if (placeSpeed > 3) { v.SetWorldVelocity(Vector3.zero); MovingVessel.angularVelocity = Vector3.zero; MovingVessel.angularMomentum = Vector3.zero; v.Translate(placeSpeed * Time.fixedDeltaTime * -_up); } else { v.SetWorldVelocity(placeSpeed * -_up); } altitude -= placeSpeed * Time.fixedDeltaTime; yield return(new WaitForFixedUpdate()); } _placingVessels.Remove(v); _hoverAdjust = 0f; }
private IEnumerator DropMoveRoutine(VesselBounds vesselBounds) { Vessel v = vesselBounds.vessel; if (!v) { yield break; } _moving = false; MoveHeight = 0; _hoverAdjust = 0f; }
private Vector3 GetRaycastPosition(VesselBounds vesselBounds) { Vector3 ZeroVector = new Vector3(0, 0, 0); RaycastHit hit; if (Physics.Raycast(vesselBounds.vessel.CoM - (vesselBounds.BottomLength * _up), -_up, out hit, (float)vesselBounds.vessel.altitude, (1 << 15) | (1 << 0))) { return(Vector3.Project(hit.point - vesselBounds.vessel.CoM, _up)); } else { return(ZeroVector); } }
private LineRenderer initLR(Vessel v, VesselBounds vbounds) { LineRenderer Lr; Lr = new GameObject().AddComponent <LineRenderer>(); Lr.material = new Material(Shader.Find("KSP/Emissive/Diffuse")); Lr.material.SetColor("_EmissiveColor", Color.green); Lr.SetWidth(0.15f, 0.15f); Lr.SetVertexCount(2); Lr.SetPosition(0, v.CoM + vbounds.bottomPoint); Lr.SetPosition(1, v.CoM + vbounds.bottomPoint + Vector3.ProjectOnPlane(v.CoM - FlightCamera.fetch.mainCamera.transform.position, vbounds.up).normalized); Lr.enabled = true; return(Lr); }
private IEnumerator DropMoveRoutine(VesselBounds vesselBounds) { Vessel v = vesselBounds.vessel; if (!v) { yield break; } _moving = false; MoveHeight = 0; _hoverAdjust = 0f; v.UpdateLandedSplashed(); _placingVessels.Remove(v); }
/// <summary> /// This vessel will be stabilized /// </summary> /// <param name="v"></param> internal static void AddVesselToStabilize(Vessel v, Vector3d rotation, bool rotationDisabled = false) { vesselToStabilize = v; if (vesselToStabilize == null) { return; } rotationVector = rotation; disableRotation = rotationDisabled; vesselTimer = stabilizationTicks; moveVesselUp = true; bounds = new VesselBounds(v); initialAltitude = v.altitude; }
public void StartMove(Vessel v, bool forceReleaseClamps) { MoveLaunch.instance.DisableGui(); MoveLaunch.instance.EnableGuiF(); if (!v) { Debug.Log("[Davinci's Move Launch] Tried to move a null vessel ...................................."); } if (v.packed) { return; } if (!_placingVessels.Contains(v) && v.LandedOrSplashed) { foreach (LaunchClamp clamp in v.FindPartModulesImplementing <LaunchClamp>()) { if (forceReleaseClamps) { clamp.Release(); } else { return; } } ShowModeMessage(); MovingVessel = v; IsMovingVessel = true; _up = (v.transform.position - v.mainBody.transform.position).normalized; _startingUp = _up; _vBounds = new VesselBounds(MovingVessel); _moving = true; MoveHeight = _vBounds.BottomLength + 0.5f; _startRotation = MovingVessel.transform.rotation; _currRotation = _startRotation; _debugLr.enabled = true; } }
public void StartMove(Vessel v, bool forceReleaseClamps) { if (!v) { Debug.Log("Vessel mover tried to move a null vessel."); } if (v.packed) { return; } if (!placingVessels.Contains(v) && v.LandedOrSplashed) { //temp foreach (var clamp in v.FindPartModulesImplementing <LaunchClamp>()) { if (forceReleaseClamps) { clamp.Release(); } else { return; } } ShowModeMessage(); movingVessel = v; isMovingVessel = true; up = (v.transform.position - v.mainBody.transform.position).normalized; startingUp = up; vBounds = new VesselBounds(movingVessel); moving = true; moveHeight = vBounds.bottomLength + 0.5f; startRotation = movingVessel.transform.rotation; currRotation = startRotation; debugLr.enabled = true; } }
float GetRaycastAltitude(VesselBounds vesselBounds) //TODO do the raycast from the bottom point of the ship, and include vessels in layer mask, so you can safely place on top of vessel { RaycastHit hit; //test if (Physics.Raycast(vesselBounds.vessel.CoM - (vesselBounds.bottomLength * up), -up, out hit, (float)vesselBounds.vessel.altitude, (1 << 15) | (1 << 0))) { return(Vector3.Project(hit.point - vesselBounds.vessel.CoM, up).magnitude); } /* * if(Physics.Raycast(vesselBounds.vessel.CoM, -up, out hit, (float)vesselBounds.vessel.altitude, (1<<15))) * { * return hit.distance; * }*/ else { return(GetRadarAltitude(vesselBounds.vessel)); } }
private void updateLR(Vessel v, VesselBounds vbounds) { LineRenderer Lr0 = renderer0 [v.id]; LineRenderer Lr1 = renderer1 [v.id]; Lr0.SetPosition(0, vbounds.bottomPoint); Lr0.SetPosition(1, vbounds.bottomPoint + v.transform.TransformPoint(v.transform.forward)); Lr0.SetPosition(2, vbounds.bottomPoint); Lr0.SetPosition(3, vbounds.bottomPoint + v.transform.TransformPoint(v.ReferenceTransform.right)); //Vector3.ProjectOnPlane(v.CoM-FlightCamera.fetch.mainCamera.transform.position, vbounds.up).normalized); Lr1.SetPosition(0, vbounds.topPoint); Lr1.SetPosition(1, vbounds.topPoint + v.transform.TransformPoint(v.ReferenceTransform.forward)); Lr1.SetPosition(2, vbounds.topPoint); Lr1.SetPosition(3, vbounds.topPoint + v.transform.TransformPoint(v.ReferenceTransform.right)); //Vector3.ProjectOnPlane(v.CoM-FlightCamera.fetch.mainCamera.transform.position, vbounds.up).normalized); //printDebug ("line: " + vbounds.bottomPoint + " -> " + (vbounds.bottomPoint + v.transform.TransformPoint(v.transform.forward))); //printDebug ("line: " + vbounds.bottomPoint + " -> " + v.ReferenceTransform.TransformPoint(v.transform.forward)); }
//TODO do the raycast from the bottom point of the ship, and include vessels in layer mask, so you can safely place on top of vessel float GetRaycastAltitude(VesselBounds vesselBounds) { RaycastHit hit; //test if(Physics.Raycast(vesselBounds.vessel.CoM - (vesselBounds.bottomLength*up), -up, out hit, (float)vesselBounds.vessel.altitude, (1<<15)|(1<<0))) { return Vector3.Project(hit.point-vesselBounds.vessel.CoM, up).magnitude; } /* if(Physics.Raycast(vesselBounds.vessel.CoM, -up, out hit, (float)vesselBounds.vessel.altitude, (1<<15))) { return hit.distance; }*/ else { return GetRadarAltitude(vesselBounds.vessel); } }
IEnumerator EndMoveRoutine(VesselBounds vesselBounds) { Vessel v = vesselBounds.vessel; if(!v) yield break; yield return new WaitForFixedUpdate(); vesselBounds.UpdateBounds(); yield return new WaitForFixedUpdate(); while(moveMode != MoveModes.Normal) { ToggleMoveMode(); } moving = false; moveHeight = 0; placingVessels.Add(vesselBounds.vessel); float bottomLength = vBounds.bottomLength; //float heightOffset = GetRadarAltitude(movingVessel) - moveHeight; float altitude = GetRaycastAltitude(vesselBounds); while(v && !v.LandedOrSplashed) { up = (v.transform.position-FlightGlobals.currentMainBody.transform.position).normalized; float placeSpeed = Mathf.Clamp(((altitude-bottomLength)*2), 0.1f, maxPlacementSpeed); if(placeSpeed > 3) { v.SetWorldVelocity(Vector3.zero); movingVessel.angularVelocity = Vector3.zero; movingVessel.angularMomentum = Vector3.zero; v.Translate(placeSpeed*Time.fixedDeltaTime * -up); } else { v.SetWorldVelocity(placeSpeed * -up); } altitude -= placeSpeed*Time.fixedDeltaTime; yield return new WaitForFixedUpdate(); } placingVessels.Remove(v); }
public void StartMove(Vessel v, bool forceReleaseClamps) { if(!v) { Debug.Log("Vessel mover tried to move a null vessel."); } if(v.packed) { return; } if(!placingVessels.Contains(v) && v.LandedOrSplashed) { //temp foreach(var clamp in v.FindPartModulesImplementing<LaunchClamp>()) { if(forceReleaseClamps) { clamp.Release(); } else { return; } } ShowModeMessage(); movingVessel = v; isMovingVessel = true; up = (v.transform.position-v.mainBody.transform.position).normalized; startingUp = up; vBounds = new VesselBounds(movingVessel); moving = true; moveHeight = vBounds.bottomLength+0.5f; startRotation = movingVessel.transform.rotation; currRotation = startRotation; debugLr.enabled = true; } }