Body

This is any sort of planet or moon. To get a variable referring to a Body, you can do this:

// "name" is the name of the body,
// like "Mun" for example.
SET MY_VAR TO BODY("name").

Note

Changed in version 0.13: A Celestial Body is now also an Orbitable, and can use all the terms described for these objects too.

Bodies’ names are added to the kerboscript language as variable names as well. This means you can use the variable Mun to mean the same thing as BODY("Mun"), and the variable Kerbin to mean the same thing as BODY("Kerbin"), and so on.

Note

Exception: If you are using a mod that replaces the stock game’s planets and moons with new bodies with new names, then there is a chance a body’s name will match an existing bound variable name in kOS and we cannot control this. Therefore if this happens, that body name will NOT become a variable name, so you can only refer to that body with the expression BODY(name). (For example, this occurred when Galileo Planet Pack had a planet called “Eta” which has the same name as the bound variable “ETA”).

Changed in version 1.0.2: This behavior was only added in kOS 1.0.2. Using a version of kOS prior to 1.0.2 will cause a name clash and broken behavior if a planet or moon exists that overrides a keyword name.

Predefined Celestial Bodies

All of the main celestial bodies in the game are reserved variable names. The following two lines do the exactly the same thing:

SET the_mun TO Mun.
SET the_mun TO Body("Mun").
  • Sun
  • Moho
  • Eve
    • Gilly
  • Kerbin
    • Mun
    • Minmus
  • Duna
    • Ike
  • Jool
    • Laythe
    • Vall
    • Tylo
    • Bop
    • Pol
  • Eeloo
structure Body
Suffix Type (units)
Every Suffix of Orbitable
NAME string
DESCRIPTION string
MASS scalar (kg)
ALTITUDE scalar (m)
ROTATIONPERIOD scalar (s)
RADIUS scalar (m)
MU scalar (\(m^3 s^{−2}\))
ATM Atmosphere
ANGULARVEL Vector in SHIP-RAW
GEOPOSITIONOF GeoCoordinates given SHIP-RAW position vector
GEOPOSITIONLATLNG GeoCoordinates given latitude and longitude values
ALTITUDEOF scalar (m)
SOIRADIUS scalar (m)
ROTATIONANGLE scalar (deg)

Note

This type is serializable.

Body:NAME

The name of the body. Example: “Mun”.

Body:DESCRIPTION

Longer description of the body, often just a duplicate of the name.

Body:MASS

The mass of the body in kilograms.

Body:ALTITUDE

The altitude of this body above the sea level surface of its parent body. I.e. the altitude of Mun above Kerbin.

Body:ROTATIONPERIOD

The length of the body’s day in seconds. I.e. how long it takes for it to make one rotation.

Body:RADIUS

The radius from the body’s center to its sea level.

Body:MU

The Gravitational Parameter of the body.

Body:ATM

A variable that describes the atmosphere of this body.

Body:ANGULARVEL

Angular velocity of the body’s rotation about its axis (its day) expressed as a vector.

The direction the angular velocity points is in Ship-Raw orientation, and represents the axis of rotation. Remember that everything in Kerbal Space Program uses a left-handed coordinate system, which affects which way the angular velocity vector will point. If you curl the fingers of your left hand in the direction of the rotation, and stick out your thumb, the thumb’s direction is the way the angular velocity vector will point.

The magnitude of the vector is the speed of the rotation.

Note, unlike many of the other parts of kOS, the rotation speed is expressed in radians rather than degrees. This is to make it congruent with how VESSEL:ANGULARMOMENTUM is expressed, and for backward compatibility with older kOS scripts.

Body:GEOPOSITIONOF(vectorPos)
Parameters:
  • vectorPosVector input position in XYZ space.

The geoposition underneath the given vector position. SHIP:BODY:GEOPOSITIONOF(SHIP:POSITION) should, in principle, give the same thing as SHIP:GEOPOSITION, while SHIP:BODY:GEOPOSITIONOF(SHIP:POSITION + 1000*SHIP:NORTH) would give you the lat/lng of the position 1 kilometer north of you. Be careful not to confuse this with :GEOPOSITION (no “OF” in the name), which is also a suffix of Body by virtue of the fact that Body is an Orbitable, but it doesn’t mean the same thing.

(Not to be confused with the Orbitable:GEOPOSITION suffix, which Body inherits from Orbitable, and which gives the position that this body is directly above on the surface of its parent body.)

Body:GEOPOSITIONLATLNG(latitude, longitude)
Parameters:
  • latitudeScalar input latitude
  • longitudeScalar input longitude
Return type:

GeoCoordinates

Given a latitude and longitude, this returns a GeoCoordinates structure for that position on this body.

(Not to be confused with the Orbitable:GEOPOSITION suffix, which Body inherits from Orbitable, and which gives the position that this body is directly above on the surface of its parent body.)

Body:ALTITUDEOF

The altitude of the given vector position, above this body’s ‘sea level’. SHIP:BODY:ALTITUDEOF(SHIP:POSITION) should, in principle, give the same thing as SHIP:ALTITUDE. Example: Eve:ALTITUDEOF(GILLY:POSITION) gives the altitude of gilly’s current position above Eve, even if you’re not actually anywhere near the SOI of Eve at the time. Be careful not to confuse this with :ALTITUDE (no “OF” in the name), which is also a suffix of Body by virtue of the fact that Body is an Orbitable, but it doesn’t mean the same thing.

Body:SOIRADIUS

The radius of the body’s sphere of influence. Measured from the body’s center.

Body:ROTATIONANGLE

The rotation angle is the number of degrees between the Solar Prime Vector and the current positon of the body’s prime meridian (body longitude of zero).

The value is in constant motion, and once per body’s day, its :rotationangle will wrap around through a full 360 degrees.