public void Update() { if (ThrusterController != null) { var rotationAxis = Vector3.zero; switch (Axis) { case RotationAxis.TopDown: rotationAxis = Vector3.up; break; case RotationAxis.Right: rotationAxis = Vector3.right; break; case RotationAxis.Up: rotationAxis = Vector3.up; break; case RotationAxis.Front: rotationAxis = Vector3.forward; break; } // You must call this before applying a new burn ThrusterController.ResetAllThrusters(); // Move Forwards/Backwards ThrusterController.ThrusterLinearBurn(Vector3.forward, Input.GetAxis("Vertical"), Space.Self); // Move Right/Left //ThrusterController.ThrusterLinearBurn(Vector3.right, Input.GetAxis("Some Other Axis"), Space.Self); // Rotate Right/Left ThrusterController.ThrusterAngularBurn(rotationAxis, Input.GetAxis("Horizontal"), Space.Self); } }
public void AddThruster(GameObject thruster) { thrusterController = thruster.GetComponent <ThrusterController>(); foreach (GameObject capsule in capsules) { capsule.transform.localPosition += new Vector3(0, 1, 0) * thrusterController.height; } foreach (GameObject _thruster in thrusters) { _thruster.transform.localPosition += new Vector3(0, 1, 0) * thrusterController.height; } thrusters.Add(thruster); thrusterControllers.Add(thrusterController); thruster.transform.parent = transform; height += thrusterController.height; thruster.transform.localPosition = new Vector3(0, 1, 0) * thrusterController.height / 2; thruster.transform.localRotation = Quaternion.identity; }
public GameObject Dettach() { GameObject dettached = thrusters[thrusters.Count - 1]; thrusters.RemoveAt(thrusters.Count - 1); thrusterControllers.RemoveAt(thrusterControllers.Count - 1); foreach (GameObject capsule in capsules) { capsule.transform.localPosition -= new Vector3(0, 1, 0) * thrusterController.height; } foreach (GameObject _thruster in thrusters) { _thruster.transform.localPosition -= new Vector3(0, 1, 0) * thrusterController.height; } thrusterController = thrusterControllers[thrusterControllers.Count - 1]; return(dettached); }
private void SetupThruster(ThrusterController con) { if (thrusterList.Contains (con)) return; if((con as CMGController) != null) { thrusterForce[con] = Vector3.zero; // Ignore force and position. thrusterPosition[con] = Vector3.zero; thrusterMoment[con] = (con as CMGController).GetMaxPower()*ship.transform.InverseTransformDirection(con.transform.up); } else { thrusterForce[con] = (ship.transform.InverseTransformDirection(con.transform.FindChild("Jet").forward*(-1)) )*con.GetMaxPower(); thrusterPosition[con] = ship.transform.InverseTransformPoint(con.transform.FindChild("Jet").position); // Relative position of the force vector thrusterMoment[con] = Vector3.Cross(thrusterForce[con],thrusterPosition[con]); } thrusterAccLinear[con] = thrusterForce[con] / ship.GetComponent<Rigidbody>().mass; thrusterAccAngular[con] = thrusterMoment[con] / ship.GetComponent<Rigidbody>().mass; thrusterPower[con] = 0f; // power between zero and one thrusterList.Add (con); }
public void Update() { if (isFirstUpdate || configCache != Me.CustomData || Me.CustomData == "") { var config = new ConfigSection("main"); config.Read(Me.CustomData); blockGroupName = config.Get <string>("block_group_name", "Heli Assist"); start_mode = config.Get <string>("start_mode", "flight"); rememberLastMode = config.Get <bool>("remember_mode", true); maxFlightPitch = config.Get <float>("max_pitch", 40.0f); maxFlightRoll = config.Get <float>("max_roll", 40.0f); maxLandingPitch = config.Get <float>("max_landing_pitch", 15.0f); maxLandingRoll = config.Get <float>("max_landing_roll", 15.0f); precisionAimFactor = config.Get <float>("precision", 16.0f); mouseSpeed = config.Get <float>("mouse_speed", 0.5f); if (Me.CustomData == "") { Me.CustomData = configCache = config.write(); } else { configCache = Me.CustomData; } } var blockGroup = GridTerminalSystem.GetBlockGroupWithName(blockGroupName); if (blockGroup == null) { throw new Exception("Could not find block group with name '" + blockGroupName + "'"); } controllerCache.Clear(); blockGroup.GetBlocksOfType <IMyShipController>(controllerCache); if (!controllerCache.Any()) { throw new Exception("Ship must have at least one ship controller"); } controller = null; foreach (var controller in controllerCache) { if (controller.IsUnderControl || (controller.IsMainCockpit && this.controller == null)) { this.controller = controller; } } if (this.controller == null) { this.controller = controllerCache.First(); } gyroCache.Clear(); blockGroup.GetBlocksOfType <IMyGyro>(gyroCache); if (!gyroCache.Any()) { throw new Exception("Ship must have atleast one gyroscope"); } thrustCache.Clear(); blockGroup.GetBlocksOfType <IMyThrust>(thrustCache); if (!thrustCache.Any()) { throw new Exception("Ship must have atleast one thruster"); } if (thrustController == null) { thrustController = new ThrusterController(controller, thrustCache); } else { thrustController.Update(controller, thrustCache); } if (gyroController == null) { gyroController = new GyroController(controller, gyroCache); } else { gyroController.Update(controller, gyroCache); } if (isFirstUpdate && rememberLastMode && IsValidMode(Storage)) { SwitchToMode(Storage); } else if (isFirstUpdate) { SwitchToMode(start_mode); } isFirstUpdate = false; updateFinished = true; }
private void Awake() { ps = ps ?? GetComponent <ParticleSystem>(); thruster = thruster ?? FindObjectOfType <ThrusterController>(); }