oakwhiz
Members-
Posts
6 -
Joined
-
Last visited
Reputation
0 NeutralProfile Information
-
About me
Bottle Rocketeer
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
-
Spawning a single part as a vessel in orbit
oakwhiz replied to oakwhiz's topic in KSP1 C# Plugin Development Help and Support
I tried the following code but it generates an exception in the chunk of code after "Set orbit params". I can't figure out what I'm doing wrong here. There has got to be a way to create a vessel dynamically. // Find the Kerbin CelestialBody CelestialBody kerbin = null; foreach (CelestialBody aBody in FlightGlobals.Bodies) { if (aBody.name == "Kerbin") { kerbin = aBody; } } // Create a new blank vessel Vessel newVessel = new Vessel(); // Add a part to the vessel Debug.Log("getPartInfoByName"); AvailablePart ap = PartLoader.getPartInfoByName("cupola"); Debug.Log("Instantiate"); UnityEngine.Object obj = UnityEngine.Object.Instantiate(ap.partPrefab); Debug.Log("newPart"); Part newPart = (Part)obj; Debug.Log("rootPart ; parts.Add()"); newPart.gameObject.name = "cupola"; newPart.partInfo = ap; newVessel.rootPart = newPart; newVessel.parts = new List<Part>(); newVessel.parts.Add(newPart); // Set vessel parameters Debug.Log("Set vessel params"); newVessel.Landed = false; newVessel.Splashed = false; newVessel.landedAt = string.Empty; newVessel.situation = Vessel.Situations.ORBITING; newVessel.vesselType = VesselType.Debris; // Set up an orbit for the vessel Debug.Log("Set orbit params"); double utTime = Planetarium.GetUniversalTime(); OrbitPhysicsManager.HoldVesselUnpack(180); // The next line tries to put the debris somewhere around the CelestialBody newVessel.orbit.UpdateFromStateVectors((UnityEngine.Random.onUnitSphere + UnityEngine.Random.insideUnitSphere) * 200000f, UnityEngine.Random.onUnitSphere * 5000f, kerbin, utTime); newVessel.orbit.Init(); newVessel.orbit.UpdateFromUT(utTime); newVessel.orbitDriver.pos = newVessel.orbit.pos.xzy; newVessel.orbitDriver.vel = newVessel.orbit.vel; // Set rotation parameters newVessel.SetRotation(UnityEngine.Random.rotation); newVessel.angularMomentum = Vector3.zero; newVessel.angularVelocity = Vector3.zero; // ??? Debug.Log("GoOnRails"); newVessel.GoOnRails(); Output: Set orbit params [Exception]: NullReferenceException: Object reference not set to an instance of an object -
I can't seem to figure out what the procedure is for taking a part and spawning it as a debris object in a particular orbit. I know that debris objects are just vessels, so I'm assuming that I have to create a Vessel, add a Part to the Vessel, add an Orbit to the Vessel, and then create a ProtoVessel from that Vessel. I haven't been able to find any documentation on instantiating a new vessel though. Any pointers as to where I should start?
-
Spaceport download link: http://kerbalspaceprogram.com/fuel-ejection-port/ Alternative download link: http://minousoft.com/downloads/FuelEjectionPort.zip The Fuel Ejection Port is simply a modified LV-1R engine designed to vent fuel as quickly as possible. Because it does not burn the fuel, it is a very inefficient thruster. Lightweight and sturdy, it is useful in emergency situations. Some possible use cases: Set a few Fuel Ejection Ports to be part of your last stage, and then bind the Abort action group to your Fuel Ejection Ports. When you hit the Abort button, all your fuel will be dumped out. Use Fuel Ejection Ports to assist in separating stages from each other, instead of using the Sepratron I solid rocket booster to do so. Impart a very large and very quick impulse on to part of your spacecraft using a Fuel Ejection Port. Since it is small and provides a large amount of thrust, you can use it to immediately change the direction of your craft. This mod may be used and redistributed freely for any purpose.