Skip to content

Commit

Permalink
fix: Adjust waypoint distance to not be so close to planets.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderson1993 committed Jan 15, 2023
1 parent f65f703 commit 983a411
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions client/src/cards/Navigation/data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ export const waypoints = t.router({
let systemId: number | null = null;
let object: Entity | undefined = undefined;
if ("entityId" in input) {
// This waypoint is being attached to a specific object in space.
object = ctx.flight?.ecs.entities.find(e => e.id === input.entityId);
if (!object) throw new Error("No object found.");
position = getObjectOffsetPosition(object, ship);
Expand All @@ -293,6 +294,7 @@ export const waypoints = t.router({
return maybeWaypoint;
}
} else if ("position" in input) {
// This waypoint is just being plopped at some random point in space.
position = input.position;
systemId = input.systemId;
} else {
Expand Down Expand Up @@ -437,14 +439,14 @@ function getObjectOffsetPosition(object: Entity, ship: Entity) {
} else {
// Take the vector that we've calculated and set the waypoint position along that line
// with a bit of distance. The distance is proportional to the radius of the object itself
// and the size of the ship: distanceFromCenter = crewShipSize * 2 + objectSize * 0.5
// and the size of the ship: distanceFromCenter = crewShipSize * 2 + objectSize * 2
const objectSize =
object.components.size?.length ||
object.components.isPlanet?.radius ||
solarRadiusToKilometers(object.components.isStar?.radius || 1) ||
1;
const distanceFromCenter =
((ship.components.size?.length || 1) / 1000) * 2 + objectSize * 1.25;
((ship.components.size?.length || 1) / 1000) * 2 + objectSize * 3;

return objectAngle.multiplyScalar(distanceFromCenter).add(objectCenter);
}
Expand Down

0 comments on commit 983a411

Please sign in to comment.