Maths question: what formula/calculation will enable me to zoom a player over any arbitrary range of zoom values, at a consistent, linear speed?
For example, being able to zoom from player.zoom = 0.0001 to 1.7 over 200 ticks, or 2.5 to 0.5 in 240 ticks, or any other from->to values and duration, always at a constant zoom rate, relative to the game world?
The problem I have is that the zoom scale is not linear. Increasing zoom from 0.1 to 0.2 results in a much larger relative movement than going from 1.0 to 1.1. Therefore my naive method of "targetZoom - startZoom / duration" results in a zoom-in that starts very fast then gets slow, and a zoom-out that starts slow then gets fast.
My maths knowledge is extremely rusty so I'd be most grateful for any help with this.
If you're wondering why I want this, and why I don't just use the new cutscene controller, here's the background: I wanted a version of the cutscene controller in which movement speed is always linear. The vanilla cutscene system is awesome, but it applies easing to every movement - meaning it's slower at the start and end of each movement than in the middle. I've raised a modding interface request for a new flag in the cutscene controller which would enable linear movement on a per-waypoint basis, and in response posila suggested a workaround of re-implementing linear zooming using player.teleport and player.zoom. He told me that this is how the old trailers did it.
This has mostly been straightforward, other than this issue with translating the zoom range into a linear movement. Unfortunately the old trailer code is no longer available for download that I can find (it's linked in this thread, but the link has been dead for a year or more.)
For reference, this is the zoom code I currently have:
Code: Select all
-- called from on_tick when a cutscene is active
if waypoint.target_zoom > cutscene.start_zoom then
waypoint.zoom_step = waypoint.zoom_step or ( waypoint.target_zoom - cutscene.start_zoom ) / waypoint.duration
cutscene.current_zoom = cutscene.current_zoom + waypoint.zoom_step
else
waypoint.zoom_step = waypoint.zoom_step or ( cutscene.start_zoom - waypoint.target_zoom ) / waypoint.duration
cutscene.current_zoom = cutscene.current_zoom - waypoint.zoom_step
end
player.zoom = cutscene.current_zoom