Fake distance scaling

0 favourites
  • 3 posts
  • I'm trying to create an effect where object shrinks as it goes farther from camera (upwards on screen) and gets bigger when it gets closer (downwards). There needs to be a set Y position that determines where the object's size is at default. I just can't seem to wrap my head around how to do this.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Choose where Y = default size 'Ydef'.

    Choose a scaling rate 'Srate'

    Sprite > set size

    Width = lerp( Sprite.ImageWidth / Srate , Sprite.ImageWidth , (Sprite.Y/Ydef) )

    Height = lerp( Sprite.ImageHeight / Srate , Sprite.ImageHeight , (Sprite.Y/Ydef) )

    In my head this works.

  • Lerp would certainly work, although it might be easier to just calculate a scale factor...

    if the top of the screen is 0 and the bottom is 800. And you want it to be full size (100%) at the bottom, and say 10% at the top then: (whenever you change the y value)

    sprite > set scale to Sprite.Y/800 * 0.9 + 0.1

    if the screen bottom is 1024 and you want it to be 20% when at the top:

    sprite > set scale to Sprite.Y/1024 * 0.8 + 0.2

    You would also want to adjust the speed as it shrinks to help sell the idea that it is moving away from you...

    EDIT: ok, just read your post again, you mention that there would be a set point where it would be full size... so you want to clamp it

    at the top of screen set it to 10% and at y=500 and below have it at 100%:

    sprite > set scale to Clamp(Sprite.Y/500 * 0.9 + 0.1, 1, 0.1)

    clamp will now prevent it from getting bigger than 100%, or smaller than 10%, so it will stay 100% between 500 and the bottom of the screen, but will scale smoothly towards the top of the screen once y is less than 500...

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