Skip to content

Commit

Permalink
Attempt to fix stations being moved by wormholes.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminAmos committed May 9, 2022
1 parent fd4a42b commit e4b3f91
Showing 1 changed file with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,30 @@ public DistortionObject(Vector2 wormholePosition, Vector2 target, float stabilit

@Override
public void update(SolGame game) {
SolShip approachingShip = ForceBeacon.pullShips(game, this, wormholePosition, null, null, ForceBeacon.MAX_PULL_DIST);
SolShip approachingShip = null;
float minShipDistance = Float.MAX_VALUE;
for (SolObject object : game.getObjectManager().getObjects()) {
if (object == this) {
continue;
}
if (!(object instanceof SolShip)) {
continue;
}

if (approachingShip != null && approachingShip.getHull().getHullConfig().getType() != HullConfig.Type.STATION
&& approachingShip.getPosition().dst(wormholePosition) < 0.1f) {
// NOTE: Setting the same ship angle causes it to deviate until it reaches NaN and crashes.
approachingShip.getHull().getBody().setTransform(target, 0);
approachingShip.receiveForce(approachingShip.getVelocity().cpy().scl(10, 10), game, true);
float distance = object.getPosition().dst(wormholePosition);
if (distance < ForceBeacon.MAX_PULL_DIST && distance < minShipDistance) {
minShipDistance = distance;
approachingShip = (SolShip) object;
}
};

if (approachingShip != null && approachingShip.getHull().getHullConfig().getType() != HullConfig.Type.STATION) {
ForceBeacon.pullShips(game, this, wormholePosition, null, null, ForceBeacon.MAX_PULL_DIST);
if (approachingShip.getPosition().dst(wormholePosition) < 0.1f) {
// NOTE: Setting the same ship angle causes it to deviate until it reaches NaN and crashes.
approachingShip.getHull().getBody().setTransform(target, 0);
approachingShip.receiveForce(approachingShip.getVelocity().cpy().scl(10, 10), game, true);
}
}
}

Expand Down

0 comments on commit e4b3f91

Please sign in to comment.