- Home /
Problem with scaling a var over height
Hi there, while working on my project found a trouble where I need an efficient way to make a function work.
Right now, the multiplier scales this way:
function fOrbHeight () {
orbHeight = orbe.transform.position.y;
if (orbHeight >= 1000){
mHeight = 0.35;
}else if (orbHeight >= 500){
mHeight = 0.30;
}else if (orbHeight >= 250){
mHeight = 0.25;
}else if (orbHeight >= 100){
mHeight = 0.20;
}else if (orbHeight >= 50){
mHeight = 0.15;
}else if (orbHeight >= 25){
mHeight = 0.10;
}else if (orbHeight >= 10){
mHeight = 0.05;
}else if (orbHeight < 10){
mHeight = 0;
}
}
Is there any way to make it infinite without working all this code?
Comment
I'm not sure what you want here since the progression is stepped and non-linear. You can use an Animation curve to define non-linear values, or you can graph these values through some function. If you are happy with a non-stepped, linear progression, you can do:
mHeight = $$anonymous$$athf.Lerp(0.0, 3.5, orbHeight / 1000);
Your answer
![](https://koobas.hobune.stream/wayback/20220613115430im_/https://answers.unity.com/themes/thub/images/avi.jpg)