API:Vessel

From Kerbal Space Program Wiki
Revision as of 22:18, 11 May 2012 by The Duck (talk | contribs)
Jump to: navigation, search

A Vessel represents a ship, or a piece of debris that was once part of a ship. You can access the vessel that your Part is part of with this.vessel. Particularly useful members are vessel.orbit, which gives your orbit, and vessel.mainBody, which gives CelestialBody whose influence you are currently under.

Useful members

Note: this is not a complete listing of the class's members. It includes only the members that someone has figured out how to use and written an explanation for. If you figure out what the other members that aren't listed here do, you should add them to the list!

void ChangeWorldVelocity(Vector3d velOffset) Adds velOffset to the vessel's velocity. This seems to happen instantaneously and without imposing any stresses on the ship. You can use this to simulate some sort of force, like gravity, that accelerates the vessel as a whole.
Vector3 findWorldCenterOfMass() Returns the center of mass of the ship, in world coordinates
void SetWorldVelocity(Vector3d vel) Sets the velocity of the vessel to the supplied velocity vector. This seems to happen instantaneously and without imposing any stresses on the ship.
bool isActiveVessel { get; } Whether this vessel is the one the player is currently controlling. This is often useful to know, as your code will run even on non-active ships when they are within a few km of the active vessel. You can enclose your code in if(this.vessel.isActiveVessel) {} if you only want to do stuff when your plugin part is on the active ship.
bool isCommandable { get; } Whether the vessel is commandable or debris. Commandable vessels can be selected from the tracking station and show up on the map with little command pod symbols. Non-commandable vessels can't and show up with debris symbols.
CelestialBody mainBody { get; } The celestial body whose sphere of influence the vessel is currently inside. You will probably use this a lot.
bool Landed Whether the vessel is currently landed on solid ground.
Orbit orbit The Orbit object storing all the information about the vessel's orbit. You can get the vessel's current velocity with vessel.orbit.GetVel()
List<Part> parts A list of the parts in the ship.
ProtoVessel protoVessel Some sort of data structure that stores saved information about the vessel. It can be useful for getting data about parts in vessels that are on rails, when vessel.parts is empty. ProtoVessel.protoPartSnapshots is a List<ProtoPartSnapshot>, with one ProtoPartSnapshot for each part in the vessel. ProtoPartSnapshot.partStateValues is a Dictionary<string, KSPParseable>, which you can store data into by overriding Part.onFlightStateSave(). This data is then accessible even if the vessel that stored the data is on rails.
Part rootPart The part at the root of the vessel's part tree, i.e., the command pod.
bool Splashed Whether the vessel is currently splashed down in the ocean.
string vesselName The name of the vessel that appears e.g. when you mouse over it on the orbital map.