Hi guys, I was wondering if someone could help me with this kind of function - in my game there’s a planet at the center of the screen. there are also asteroids that spawns from time to time directing the planet and go towards it. do someone have any idea how do I make the asteroids scale up and down depends of their position from the planet( center of the screen )? Help would be great!
If I’m getting it right, you can check their distance to the center of the screen and use .xScale/.yScale to scale your objects. You can also use proportioning to scale your planets in a meaningful manner like “if it has a scale of 1 at the end of the screen, how much will it be near the center?”.
thats exactly what I ment! Just dont know how to approach this - your second suggestion. lets say that I measures the distance between the spawned object and the center of the screen what do I do next?
in psuedocode, @bgmadclown’s use of “proportion” was likely meant to suggest something like this:
desiredScale = minimumScale + (distanceFromCenter / maxDistanceFromCenter) \* (maximumScale-minimumScale)
that’s just a “lerp” (linear interpolation), which could also be written (still pseudocode)
t = distanceFromCenter / maxDistanceFromCenter -- this is your "proportion", a parametric on [0..1] desiredScale = lerp(minimumScale, maximumScale, t)
that form is (maybe?) conceptually easier if you need to invert it - you don’t specify whether near/far is large/small
hth
Made it! thank you all!
If I’m getting it right, you can check their distance to the center of the screen and use .xScale/.yScale to scale your objects. You can also use proportioning to scale your planets in a meaningful manner like “if it has a scale of 1 at the end of the screen, how much will it be near the center?”.
thats exactly what I ment! Just dont know how to approach this - your second suggestion. lets say that I measures the distance between the spawned object and the center of the screen what do I do next?
in psuedocode, @bgmadclown’s use of “proportion” was likely meant to suggest something like this:
desiredScale = minimumScale + (distanceFromCenter / maxDistanceFromCenter) \* (maximumScale-minimumScale)
that’s just a “lerp” (linear interpolation), which could also be written (still pseudocode)
t = distanceFromCenter / maxDistanceFromCenter -- this is your "proportion", a parametric on [0..1] desiredScale = lerp(minimumScale, maximumScale, t)
that form is (maybe?) conceptually easier if you need to invert it - you don’t specify whether near/far is large/small
hth
Made it! thank you all!