SpaceCenter#
- class SpaceCenter#
Provides functionality to interact with Kerbal Space Program. This includes controlling the active vessel, managing its resources, planning maneuver nodes and auto-piloting.
- IList<string> Expansions { get; }#
The names of the installed expansions, for example
"Serenity"(Breaking Ground) or"MakingHistory"(Making History).- Game Scenes:
All
- IList<LaunchSite> LaunchSites { get; }#
A list of available launch sites.
- Game Scenes:
All
- IDictionary<string, CelestialBody> Bodies { get; }#
A dictionary of all celestial bodies (planets, moons, etc.) in the game, keyed by the name of the body.
- Game Scenes:
All
- CelestialBody TargetBody { get; set; }#
The currently targeted celestial body.
- Game Scenes:
Flight
- DockingPort TargetDockingPort { get; set; }#
The currently targeted docking port.
- Game Scenes:
Flight
- void ClearTarget ()#
Clears the current target.
- Game Scenes:
Flight
- IList<string> LaunchableVessels (string craftDirectory)#
Returns a list of vessels from the given craftDirectory that can be launched.
- Parameters:
craftDirectory – Name of the directory in the current saves “Ships” directory. For example
"VAB"or"SPH".
- Game Scenes:
All
- void LaunchVessel (string craftDirectory, string name, string launchSite, IList<string> crew = null, bool recover = true, string flagUrl = "")#
Launch a vessel.
- Parameters:
craftDirectory – Name of the directory in the current saves “Ships” directory, that contains the craft file. For example
"VAB"or"SPH".name – Name of the vessel to launch. This is the name of the “.craft” file in the save directory, without the “.craft” file extension.
launchSite – Name of the launch site. For example
"LaunchPad"or"Runway".crew – The Kerbals to place in the craft, by name. Controls how the craft is crewed, as described in the remarks. If null, defaults to
new System.Collections.Generic.List<string> { }.recover – If true and there is a vessel on the launch site, recover it before launching.
flagUrl – If not
null, the asset URL of the mission flag to use for the launch.
- Game Scenes:
All
Note
The crew parameter controls how the craft is crewed:
If
null, the craft’s default crew assignments are used.If an empty list, the craft is launched with no crew.
Otherwise, the named Kerbals are placed in the craft in the order given: the first name takes the first seat, the second name the next seat, and so on, scanning the craft’s parts in order. No other Kerbals are hired to fill remaining seats. Throws an exception, without launching, if a name does not match an available Kerbal or the craft has too few seats for the requested crew.
Throws an exception if any of the games pre-flight checks fail.
- void LaunchVesselFromVAB (string name, bool recover = true)#
Launch a new vessel from the VAB onto the launchpad.
- Parameters:
name – Name of the vessel to launch.
recover – If true and there is a vessel on the launch pad, recover it before launching.
- Game Scenes:
All
Note
This is equivalent to calling
SpaceCenter.LaunchVesselwith the craft directory set to “VAB” and the launch site set to “LaunchPad”. Throws an exception if any of the games pre-flight checks fail.
- void LaunchVesselFromSPH (string name, bool recover = true)#
Launch a new vessel from the SPH onto the runway.
- Parameters:
name – Name of the vessel to launch.
recover – If true and there is a vessel on the runway, recover it before launching.
- Game Scenes:
All
Note
This is equivalent to calling
SpaceCenter.LaunchVesselwith the craft directory set to “SPH” and the launch site set to “Runway”. Throws an exception if any of the games pre-flight checks fail.
- Editor Editor { get; }#
The editor, for inspecting the vessel that is being constructed.
- Game Scenes:
Editor Vab, Editor Sph
- void Save (string name)#
Save the game with a given name. This will create a save file called
name.sfsin the folder of the current save game.- Parameters:
name – Name of the save.
- Game Scenes:
All
- void Load (string name)#
Load the game with the given name. This will create a load a save file called
name.sfsfrom the folder of the current save game.- Parameters:
name – Name of the save.
- Game Scenes:
All
- void Quicksave ()#
Save a quicksave.
- Game Scenes:
All
Note
This is the same as calling
SpaceCenter.Savewith the name “quicksave”.
- void Quickload ()#
Load a quicksave.
- Game Scenes:
All
Note
This is the same as calling
SpaceCenter.Loadwith the name “quicksave”.
- bool CanSave { get; }#
Whether the game can be saved.
- Game Scenes:
All
Note
The game cannot be saved in some flight states, e.g. while under acceleration or moving over the surface. Setting
KRPC.GameSceneto leave flight saves the game only when this is true.
- void RevertToLaunch ()#
Revert the current flight to launch.
- Game Scenes:
All
- void TransferCrew (CrewMember crewMember, Part targetPart)#
Transfers a crew member to a different part.
- Parameters:
crewMember – The crew member to transfer.
targetPart – The part to move them to.
- Game Scenes:
Flight
Whether the navball is visible.
- Game Scenes:
Flight
- AltimeterMode AltimeterMode { get; set; }#
The current mode of the altimeter.
- Game Scenes:
Flight
- double G { get; }#
The value of the gravitational constant G in \(N(m/kg)^2\).
- Game Scenes:
All
- double BuoyancyScalar { get; }#
The multiplier the game applies to every buoyant force.
- Game Scenes:
All
Note
Stock KSP sets it to 1.2. A buoyant force is a fifth larger than Archimedes’ principle alone gives.
- float WarpRate { get; }#
The current warp rate. This is the rate at which time is passing for either on-rails or physical time warp. For example, a value of 10 means time is passing 10x faster than normal. Returns 1 if time warp is not active.
- Game Scenes:
Space Center, Flight, Tracking Station
- float WarpFactor { get; }#
The current warp factor. This is the index of the rate at which time is passing for either regular “on-rails” or physical time warp. Returns 0 if time warp is not active. When in on-rails time warp, this is equal to
SpaceCenter.RailsWarpFactor, and in physics time warp, this is equal toSpaceCenter.PhysicsWarpFactor.- Game Scenes:
Space Center, Flight, Tracking Station
- int RailsWarpFactor { get; set; }#
The time warp rate, using regular “on-rails” time warp. A value between 0 and 7 inclusive. 0 means no time warp. Returns 0 if physical time warp is active.
If requested time warp factor cannot be set, it will be set to the next lowest possible value. For example, if the vessel is too close to a planet. See the KSP wiki for details.
- Game Scenes:
Space Center, Flight, Tracking Station
Note
Outside the flight scene, every factor can be set.
- int PhysicsWarpFactor { get; set; }#
The physical time warp rate. A value between 0 and 3 inclusive. 0 means no time warp. Returns 0 if regular “on-rails” time warp is active.
- Game Scenes:
Flight
- bool CanRailsWarpAt (int factor = 1)#
Returns
trueif regular “on-rails” time warp can be used, at the specified warp factor. The maximum time warp rate is limited by various things, including how close the active vessel is to a planet. See the KSP wiki for details.- Parameters:
factor – The warp factor to check.
- Game Scenes:
Space Center, Flight, Tracking Station
Note
Outside the flight scene, every valid factor can be used.
- int MaximumRailsWarpFactor { get; }#
The current maximum regular “on-rails” warp factor that can be set. A value between 0 and 7 inclusive. See the KSP wiki for details.
- Game Scenes:
Space Center, Flight, Tracking Station
Note
Outside the flight scene, this is the highest factor.
- void WarpTo (double ut, float maxRailsRate = 1e+05f, float maxPhysicsRate = 2.0f)#
Uses time acceleration to warp forward to a time in the future, specified by universal time ut. This call blocks until the desired time is reached. Uses regular “on-rails” or physical time warp as appropriate. For example, physical time warp is used when the active vessel is traveling through an atmosphere. When using regular “on-rails” time warp, the warp rate is limited by maxRailsRate, and when using physical time warp, the warp rate is limited by maxPhysicsRate.
- Parameters:
ut – The universal time to warp to, in seconds.
maxRailsRate – The maximum warp rate in regular “on-rails” time warp.
maxPhysicsRate – The maximum warp rate in physical time warp.
- Returns:
When the time warp is complete.
- Game Scenes:
Space Center, Flight, Tracking Station
Note
Outside the flight scene, only regular “on-rails” time warp is used. Throws an exception if the game scene changes during the time warp.
- Tuple<double, double, double> TransformPosition (Tuple<double, double, double> position, ReferenceFrame from, ReferenceFrame to)#
Converts a position from one reference frame to another.
- Parameters:
position – Position, as a vector, in reference frame from.
from – The reference frame that the position is in.
to – The reference frame to covert the position to.
- Returns:
The corresponding position, as a vector, in reference frame to.
- Game Scenes:
All
- Tuple<double, double, double> TransformDirection (Tuple<double, double, double> direction, ReferenceFrame from, ReferenceFrame to)#
Converts a direction from one reference frame to another.
- Parameters:
direction – Direction, as a vector, in reference frame from.
from – The reference frame that the direction is in.
to – The reference frame to covert the direction to.
- Returns:
The corresponding direction, as a vector, in reference frame to.
- Game Scenes:
All
- Tuple<double, double, double, double> TransformRotation (Tuple<double, double, double, double> rotation, ReferenceFrame from, ReferenceFrame to)#
Converts a rotation from one reference frame to another.
- Parameters:
rotation – Rotation, as a quaternion of the form \((x, y, z, w)\), in reference frame from.
from – The reference frame that the rotation is in.
to – The reference frame to covert the rotation to.
- Returns:
The corresponding rotation, as a quaternion of the form \((x, y, z, w)\), in reference frame to.
- Game Scenes:
All
- Tuple<double, double, double> TransformVelocity (Tuple<double, double, double> position, Tuple<double, double, double> velocity, ReferenceFrame from, ReferenceFrame to)#
Converts a velocity (acting at the specified position) from one reference frame to another. The position is required to take the relative angular velocity of the reference frames into account.
- Parameters:
position – Position, as a vector, in reference frame from.
velocity – Velocity, as a vector that points in the direction of travel and whose magnitude is the speed in meters per second, in reference frame from.
from – The reference frame that the position and velocity are in.
to – The reference frame to covert the velocity to.
- Returns:
The corresponding velocity, as a vector, in reference frame to.
- Game Scenes:
All
- double RaycastDistance (Tuple<double, double, double> position, Tuple<double, double, double> direction, ReferenceFrame referenceFrame)#
Cast a ray from a given position in a given direction, and return the distance to the hit point. If no hit occurs, returns infinity.
- Parameters:
position – Position, as a vector, of the origin of the ray.
direction – Direction of the ray, as a unit vector.
referenceFrame – The reference frame that the position and direction are in.
- Returns:
The distance to the hit, in meters, or infinity if there was no hit.
- Game Scenes:
All
- Part RaycastPart (Tuple<double, double, double> position, Tuple<double, double, double> direction, ReferenceFrame referenceFrame)#
Cast a ray from a given position in a given direction, and return the part that it hits. If no hit occurs, returns
null.- Parameters:
position – Position, as a vector, of the origin of the ray.
direction – Direction of the ray, as a unit vector.
referenceFrame – The reference frame that the position and direction are in.
- Returns:
The part that was hit or
nullif there was no hit.- Game Scenes:
Flight
- bool FARAvailable { get; }#
Whether Ferram Aerospace Research is installed.
- Game Scenes:
All
- void CreateKerbal (string name, string job, bool male)#
Creates a Kerbal.
- Parameters:
- Game Scenes:
All
- CrewMember GetKerbal (string name)#
Find a Kerbal by name.
- Parameters:
- Game Scenes:
All
- MapFilterType MapFilter { get; set; }#
The visible objects in map mode.
- Game Scenes:
All
- void Screenshot (string filePath, int scale = 1)#
Saves a screenshot.
- Parameters:
filePath – The path of the file to save.
scale – Resolution scaling factor
- Game Scenes:
Flight
- WarpMode WarpMode { get; }#
The current time warp mode. Returns
WarpMode.Noneif time warp is not active,WarpMode.Railsif regular “on-rails” time warp is active, orWarpMode.Physicsif physical time warp is active.- Game Scenes:
Space Center, Flight, Tracking Station
- WaypointManager WaypointManager { get; }#
The waypoint manager.
- Game Scenes:
Flight
- ContractManager ContractManager { get; }#
The contract manager.
- Game Scenes:
Space Center, Flight, Tracking Station, Editor Vab, Editor Sph
- AlarmManager AlarmManager { get; }#
The alarm manager.
- Game Scenes:
All
- enum GameMode#
The game mode. Returned by
GameMode- Sandbox#
Sandbox mode.
- Career#
Career mode.
- Science#
Science career mode.
- ScienceSandbox#
Science sandbox mode.
- Mission#
Mission mode.
- MissionBuilder#
Mission builder mode.
- Scenario#
Scenario mode.
- ScenarioNonResumable#
Scenario mode that cannot be resumed.
- enum AltimeterMode#
The mode of the altitude reported on the altimeter. See
SpaceCenter.AltimeterMode.- DEFAULT#
The altimeter is in the default mode.
- ASL#
The altimeter is in the “Above Sea Level” mode.
- AGL#
The altimeter is in the “Above Ground Level” mode.
- enum WarpMode#
The time warp mode. Returned by
WarpMode- Rails#
Time warp is active, and in regular “on-rails” mode.
- Physics#
Time warp is active, and in physical time warp mode.
- None#
Time warp is not active.
- enum MapFilterType#
The set of things that are visible in map mode. These may be combined with bitwise logic.
- All#
Everything.
- None#
Nothing.
- Debris#
Debris.
- Unknown#
Unknown.
- SpaceObjects#
SpaceObjects.
- Probes#
Probes.
- Rovers#
Rovers.
- Landers#
Landers.
- Ships#
Ships.
- Stations#
Stations.
- Bases#
Bases.
- EVAs#
EVAs.
- Flags#
Flags.
- Plane#
Planes.
- Relay#
Relays.
- Site#
Launch Sites.
- DeployedScienceController#
Deployed Science Controllers.
- struct LaunchSite#
A place where craft can be launched from. More of these can be added with mods like Kerbal Konstructs.
- LaunchSite (string name, CelestialBody body, EditorFacility editorFacility)#
Construct a LaunchSite from the values of its fields.
- CelestialBody Body { get; }#
The celestial body the launch site is on.
- EditorFacility EditorFacility { get; }#
Which editor is normally used for this launch site.
- enum EditorFacility#
Editor facility. See
LaunchSite.EditorFacility.- VAB#
Vehicle Assembly Building.
- SPH#
Space Plane Hanger.
- None#
None.