How to "synchronize" zoom factor and camera swipe?

Hi,

I have a scene with an orthographic camera. I can zoom-in/zoom-out by changing the orthographic size of the camera. At the same time I can swipe the camera around by touch input. The “cameraDump” defines, how quickly the camera moves when executing a swipe gesture (a bigger value means a slower movement of the camera). What I want now is that the swipe (= camera movement) is performed slower, the higher the zoom level is. In other words:

the lower my orthographic size of the camera, the higher my camera speed.

How can I do this? I guess, it’s more a mathematical question :slight_smile:

Thanks for help!

If you take the Max Size of the camera and subtract it from your current camera size it will give you an inverse.

Check it:

Suppose you have a line that represents the size of the camera:

min max
<-----------------x>

min max
<----x------------->

Subtracting the current value from the maximum size should yield the number that would be your speed.

min max
<----x|-------------|>

the lower the value…

min max
<-x|----------------|>

… the larger the range.

In combination with a mapping function like:

public static float MapFromTo(float unmappedFloat, Vector2 fromRange, Vector2 toRange)
{
	return (unmappedFloat-fromRange.x)/(fromRange.y-fromRange.x)*(toRange.y-toRange.x)+toRange.x;
}

you could then project that number into a space that you desire with respect to the original bounds.

Hope this helps!

-Kirk