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

    construct.net/en/tutorials/zoom-smoothly-jump-speed-2537

    The Simplest way is using Fib Code

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Wow thanks guys that's awesome!

  • 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.

    Thanks for your help

    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.

    So instead of:

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

    You would instead do:

    Percentage of speed = (current_speed / overall_max_speed)

    So the entire equation ends up as:

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

  • Awesome, thanks again!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)