My Solution for Perceived Roll Due To FOV

Hey there! Decided to adjust my ship’s roll to compensate for the FOV distortion rather than change my FOV, (because I liked it). For anyone interested, here’s my solution:

public class Player : MonoBehaviour {

    [Tooltip("In ms^-1")] [SerializeField] float maxSpeed = 15f;
    [Tooltip("In m")] [SerializeField] float xMaxRange = 7f;
    [Tooltip("In m")] [SerializeField] float yMinRange = 2f;
    [Tooltip("In m")] [SerializeField] float yMaxRange = 7f;

    [SerializeField] float positionPitchFactor = -2f;
    [SerializeField] float controlPitchFactor = -30f;
    [SerializeField] float positionYawFactor = 3f;
    [SerializeField] float controlRollFactor = -20f;
    [SerializeField] float positionRollFactor = -1.15f; // to correct for perceived roll due to FOV

    float xThrow, yThrow;
    float yStartPosition;

    // Use this for initialization
    void Start () {
        yStartPosition = transform.localPosition.y;
	}
	
	// Update is called once per frame
	void Update ()
    {
        ProcessTranslation();
        ProcessRotation();
    }

    private void ProcessTranslation()
    {
        xThrow = CrossPlatformInputManager.GetAxis("Horizontal");
        yThrow = CrossPlatformInputManager.GetAxis("Vertical");

        float xOffsetThisFrame = xThrow * maxSpeed * Time.deltaTime;
        float yOffsetThisFrame = yThrow * maxSpeed * Time.deltaTime;

        float rawXPos = transform.localPosition.x + xOffsetThisFrame;
        float rawYPos = transform.localPosition.y + yOffsetThisFrame;

        float clampedXPos = Mathf.Clamp(rawXPos, -xMaxRange, xMaxRange);
        float clampedYPos = Mathf.Clamp(rawYPos, -yMinRange + yStartPosition, yMaxRange + yStartPosition);

        transform.localPosition = new Vector3(clampedXPos, transform.localPosition.y, transform.localPosition.z);
        transform.localPosition = new Vector3(transform.localPosition.x, clampedYPos, transform.localPosition.z);
    }

    private void ProcessRotation()
    {
        float pitchDueToPosition = transform.localPosition.y * positionPitchFactor;
        float pitchDueToControlThrow = yThrow * controlPitchFactor;
        float pitch = pitchDueToPosition + pitchDueToControlThrow;

        float yawDueToPosition = transform.localPosition.x * positionYawFactor;
        float yaw = yawDueToPosition;

        float yPosRelativeToScreen = transform.localPosition.y / Mathf.Abs(yStartPosition + yMaxRange);
        float rollDueToPosition = transform.localPosition.x * yPosRelativeToScreen * positionRollFactor;
        float rollDueToControlThrow = xThrow * controlRollFactor;
        float roll = rollDueToPosition + rollDueToControlThrow;

        transform.localRotation = Quaternion.Euler( pitch, yaw, roll );
    }
}

Before screenshot:

And after:

Thank you, as I’m having the same issues, I’ll use your code as a start.

Privacy & Terms