# Camera zoom in/out in relation to speed

0 favourites
• 10 posts
From the Asset Store
All popular touch mechanics - scrolling, zooming, swiping
• Hi all, just searching for how to achieve this, an old c2 post had a link to youtube vid that no longer exists. Just want to adjust camera zoom in/out in relation to speed. I presume you need a global variable with sprite speed and also layout scale but don't know how the lerp code works.

Thanks for any help

Alex

• How will you be using it? Is it for a racing game? Should the zoom work more slowly as the speed increases? Or zoom faster as the speed increases?

• Hi Fib,

It's a side scrolling flying game, I want it to zoom out the faster the player goes then zoom back when slowing down, allowing the player to see more of the layout the faster they go.

Thanks

• It's a math problem mostly and there's lots of ways to do it depending upon the type of motion you want. But the simplest way I would go about it is to do it is with percentages and linear motion. Here's an example.

First you need a number that goes up when your speed is down, and down when your speed is up. I chose to express the speed as a percentage, then take the inverse of it. So when current_speed goes up, the output of the equation goes down.

Inverse percentage of speed = 1 - (current_speed / overall_max_speed)

Then I decided to incorporate a min and max zoom level so you have a definable range. So first I multiplied the inverse percent of speed to scale the max zoom level.

Scaled max zoom = max_zoom * (1 - (current_speed / overall_max_speed))

Then I just add the min zoom to the whole thing to ensure we don't ever get zero, and also so we can control the lowest zoom level. So here's the entire equation.

Set Layout Scale = min_zoom + (max_zoom * (1 - (current_speed / overall_max_speed)))

The zoom range is between min_zoom and (max_zoom + min_zoom).

I hope that helps!

• Here a c3p file with some exemples of Zooming Including Speed

The Simplest way is using Fib Code

• Wow thanks guys that's awesome!

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• I did a Live preview if anyone is interested

rafaeltrigo.000webhostapp.com/zoom

• Hi Fib Thanks again for this code, I've been experimenting a lot with it, I'm just wondering how I can inverse it? so that the faster the object goes the greater the zoom.

Alex

• Hey, you're welcome. I think you would just stop inversing the speed percentage. That way if your current_speed increases then max_zoom will also increase.

Inverse percentage of speed = 1 - (current_speed / overall_max_speed)