The component we'll be focusing on is the updatePhysics() function - here's a code sample from that section:
;====== UPDATE PHYSICS =======================================
player.playerClass = Object.playerClass( localPlayer )
planetoid.planetoidClass = Object.planetoidClass( player\planetoid )
LinePick( EntityX( player\character ), EntityY( player\character ), EntityZ( player\character ), EntityX( planetoid\mesh ) - EntityX( player\character ), EntityY( planetoid\mesh ) - EntityY( player\character ), EntityZ( planetoid\mesh ) - EntityZ( player\character ) )
AlignToVector( player\character, PickedNX(), PickedNY(), PickedNZ(), 2, 1 )
player\nX# = PickedNX()
player\nY# = PickedNY()
player\nZ# = PickedNZ()
If (EntityCollided( player\character, STATIC ) )
player\jumpTimer = MilliSecs()
player\vX# = 0
player\vY# = 0
player\vZ# = 0
player\vX# = player\vX# - PickedNX()
player\vY# = player\vY# - PickedNY()
player\vZ# = player\vZ# - PickedNZ()
TranslateEntity( player\character, player\vX#, player\vY#, player\vZ# )
distance = EntityDistance( player\character, planetoid \mesh )
For planetoid.planetoidClass = Each planetoidClass
If ( EntityDistance( player\character, planetoid\mesh ) < distance ) Then player\planetoid = Handle( planetoid )
The first two lines in this function retrieve our player and the planetoid he inhabits. This sets us up to apply the calculations, which will allow gravity to occur between them. Next we cast a ray from our character's local center to the planetoids local center.
This call requires 6 parameters. The first 3 are the starting point of the ray and the last 3 are the distance along the (x, y, z) axes to cast our ray. We don't use the ray itself to calculate gravity. Instead we only use the ray to find a polygon between the player and the planetoid and extract its surface normal.
The first thing we do with the surface normal is character alignment. The call to AlignToVector() has 6 parameters; the object to be aligned, the vector to align to, the axis to align along, and the speed at which we interpolate or snap to this alignment.