Map the difference of two numbers to a certain min and max range

I’m making a game which monitors how far a person swipes on their phone. I only need to capture the data if they are swiping downward (from top of phone toward bottom). The way the coordinate system works, the 0,0 point is in the lower left of the screen, and the y value at the top of the screen is about 420.

What I need to is capture the starting position, the current position as they drag down with their finger, and as they drag, calculate the difference of these two numbers in order to rotate an object (to a maximum rotation of 180 degrees). So essentially it would be something like:

If swipe direction is downward:

object rotation equals difference between start position and current position with a min of 0 and a max of 180. Anybody know how to write a formula for that?

That’s standard math using cross-multiplication (“Dreisatz”):

float MapInterval(float val, float srcMin, float srcMax, float dstMin, float dstMax) {
    if (val>=srcMax) return dstMax;
    if (val<=srcMin) return dstMin;
    return dstMin + (val-srcMin) / (srcMax-srcMin) * (dstMax-dstMin);
}

The functions that you’ll need for this are Vector2.Distance and Mathf.Clamp. You can find both of them in the Script Reference.