Skip to content

Commit

Permalink
Work around an issue in CHoverAirMoveType::UpdateBanking() when circl…
Browse files Browse the repository at this point in the history
…ingPos == owner->pos caused NaNs
  • Loading branch information
lhog committed Dec 26, 2023
1 parent a9e11ed commit fcdb49b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions rts/Sim/MoveTypes/HoverAirMoveType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,11 @@ void CHoverAirMoveType::UpdateBanking(bool noBanking)
rightDir2D = frontDir.cross(UpVector);


if (!owner->upright)
wantedPitch = (circlingPos.y - owner->pos.y) / circlingPos.distance(owner->pos);
if (!owner->upright) {
// std::max() is here to guard around the case when circlingPos == owner->pos,
// which caused NaNs all over the place
wantedPitch = (circlingPos.y - owner->pos.y) / std::max(0.01f, circlingPos.distance(owner->pos));
}

wantedPitch *= (aircraftState == AIRCRAFT_FLYING && flyState == FLY_ATTACKING && circlingPos.y != owner->pos.y);
currentPitch = mix(currentPitch, wantedPitch, 0.05f);
Expand Down

0 comments on commit fcdb49b

Please sign in to comment.