View pitch limits are bugged in VehicleWeaponPawns

Issue #244 resolved
Matt Hands created an issue

In a VWP, the LimitPitch() function returns LocalLimitPitch(), to control the player's view pitch limit (this is separate to the VehicleWeapon, which has its own movement limits).

I'm pretty sure the LocalLimitPitch() function in ROVehicleWeaponPawn is bugged and will not always operate as designed. This block for multi-position weapons exclusively refers to the ViewPitchUpLimit and ViewPitchDownLimit from the DriverPositions array, which is to be expected. But there is one reference to PitchDownLimit, which seems like a simple typo, potentially giving a screwed up calculation:

if (pitch > DriverPositions[DriverPositionIndex].ViewPitchUpLimit && pitch < DriverPositions[DriverPositionIndex].ViewPitchDownLimit)
{
    if (pitch - DriverPositions[DriverPositionIndex].ViewPitchUpLimit < PitchDownLimit - pitch)
        pitch = DriverPositions[DriverPositionIndex].ViewPitchUpLimit;
    else
        pitch = DriverPositions[DriverPositionIndex].ViewPitchDownLimit;
}

The line is determining whether a pitch that is outside of the limits is closer to the up limit or the down limit, so it gets capped to the one it's closest to.

I believe the PitchUpLimit & PitchDownLimit aren't relevant to multi-position VWPs, as they are superseded by the DriverPositions array, with it's separate view limits for each position. So they may not be set or may have completely different values to the array's real view pitch limits.

Affects cannon & MG pawns. Does not effect passenger pawns as never multi-position.

Comments (1)

  1. Matt Hands reporter

    Fixed in commit 47fe616.

    ps - I couldn't see a simple way to distil this down to a one line min/max calculation, as we have on several similar functions. The unique nature of the down limit being higher than the up limit, instead of being a negative value, seems to prevent a really simple solution. At least without manipulating the values or adding complex conditional statements.

  2. Log in to comment