Skip to content

Instantly share code, notes, and snippets.

@Starwaster
Created January 25, 2018 16:43
Show Gist options
  • Save Starwaster/f0264f3d8798340be189cf8e0b2d97ce to your computer and use it in GitHub Desktop.
Save Starwaster/f0264f3d8798340be189cf8e0b2d97ce to your computer and use it in GitHub Desktop.
Modified version of KoS terrain height calculator
Vector3d worldRayCastStart = body.GetWorldSurfacePosition(latitude, longitude, body.Radius + 50000);
// a point a bit below it, to aim down to the terrain:
Vector3d worldRayCastStop = body.GetWorldSurfacePosition(latitude, longitude, body.Radius + 49900);
RaycastHit hit;
if (Physics.Raycast(worldRayCastStart, (worldRayCastStop - worldRayCastStart), out hit, float.MaxValue, 32768))
{
// Ensure hit is on the topside of planet, near the worldRayCastStart, not on the far side.
if (Mathf.Abs(hit.distance) <= 50000)
{
// Okay a hit was found, use it instead of PQS alt:
alt = ((body.Radius + 50000) - hit.distance);
}
else
alt = 0;
}
return alt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment