# Fake distance scaling

Get help using Construct 2

### » Wed Mar 01, 2017 5:56 pm

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.
B
22
S
7
G
4
Posts: 235
Reputation: 3,503

### » Wed Mar 01, 2017 8:33 pm

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) )

B
33
S
18
G
29
Posts: 2,493
Reputation: 21,450

### » Wed Mar 01, 2017 9:54 pm

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...
B
99
S
35
G
20
Posts: 438
Reputation: 17,960