Skip to content

Commit

Permalink
Fix waypoints to not be created below ground if the body isn't loaded…
Browse files Browse the repository at this point in the history
…. In this case a MaxTerrainHeight offset is added to the altitude of the waypoint.
  • Loading branch information
Falki-git committed Feb 8, 2024
1 parent 81115c0 commit 9368c09
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/SpaceWarp.Game/API/Game/Waypoints/Waypoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ namespace SpaceWarp.API.Game.Waypoints;
[PublicAPI]
public class Waypoint
{


private SimulationObjectModel _waypointObject;

/// <summary>
Expand Down Expand Up @@ -130,7 +128,17 @@ public Waypoint(double latitude, double longitude, double? altitudeFromRadius =
var body = celestialBodies.Find(c => c.Name == bodyName);
if (body == null)
throw new Exception($"Could not create waypoint as there is no body with the name of {bodyName}");
altitudeFromRadius ??= body.SurfaceProvider.GetTerrainAltitudeFromCenter(latitude, longitude) - body.radius;
if (altitudeFromRadius == null)
{
altitudeFromRadius = body.SurfaceProvider.GetTerrainAltitudeFromCenter(latitude, longitude) - body.radius;

// if the local space of the body is not loaded, then the altitude of the terrain from its center is equal to the radius
if (altitudeFromRadius == 0)
{
// we'll set the altitude to the MaxTerrainHeight, so that the waypoint will always appear above the surface
altitudeFromRadius += body.MaxTerrainHeight;
}
}
AltitudeFromRadius = altitudeFromRadius.Value;
_state = waypointState;
if (_state == WaypointState.Visible)
Expand Down

0 comments on commit 9368c09

Please sign in to comment.