Body

BODY(name)

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").

Bodies are also Orbitable, and as such have all the associated suffixes.

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.

BODYEXISTS(name)

To check whether a Body exists, you can use this boolean function:

SET MUN_EXISTS TO BODYEXISTS("Mun").
IF MUN_EXISTS PRINT "Mun Exists." ELSE PRINT "Mun does not exist.".

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)

HASOCEAN

Boolean

HASSOLIDSURFACE

Boolean

ORBITINGCHILDREN

List

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:HASOCEAN

True if this body has an ocean. Example: In the stock solar system, this is True for Kerbin and False for Mun.

Body:HASSOLIDSURFACE

True if this body has a solid surface. Example: In the stock solar system, this is True for Kerbin and False for Jool.

Body:ORBITINGCHILDREN

A list of the bodies orbiting this body. Example: In the stock solar system, Kerbin:orbitingchildren is a list two things: Mun and Minmus.

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 number of seconds it takes the body to rotate around its own axis. This is the sidereal rotation period which can differ from the length of a day due to the fact that the body moves a bit further around the Sun while it’s rotating around its own axis.

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 sidereal 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, in radians.

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.

Return type

GeoCoordinates

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 position of the body’s prime meridian (body longitude of zero).

The value is in constant motion, and once per body’s rotation period (“sidereal day”), its :rotationangle will wrap around through a full 360 degrees.