• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Linear interpolation (lerp) analogues?

E

Edwin

Guest
I want to slowly "move" my value from, for example: 2 to 0 without "this":
Webp.net-gifmaker.gif

Sometimes, values that need to slowly decrease or increase are starting to "twitch", trying to get into a certain interval or position.

How to fix it?
 
E

Edwin

Guest
what are you doing presently that is responsible for that twitching?
For example, in movement: if the speed variable is not rounded or floored (I forgot how it's called), it can twitch to make the hspeed value equal 0, but can not do it.
 
D

dannyjenn

Guest
The twitching seems like you're overshooting the 0, then overcorrecting, then overshooting again, and so on. You could probably solve that in a number of ways. e.g. max(0,amount) will prevent it from overshooting. min(0,amount) will prevent it from overcorrecting.
 

samspade

Member
I want to slowly "move" my value from, for example: 2 to 0 without "this":
View attachment 20575

Sometimes, values that need to slowly decrease or increase are starting to "twitch", trying to get into a certain interval or position.

How to fix it?
Remember to post your code so we don't have to guess at what is going on.
 

TheSnidr

Heavy metal viking dentist
GMC Elder
Smoothstep is a useful function similar to lerp, but allows for smoother movements.
Since you haven't posted any code, we can only guess how you made your thing bounce back and forth. So please post your code, we're not playing the guessing game.

For making something move smoothly from one place to another, I personally like setting the movement speed to a factor times the distance. This makes an object move fast in the beginning, then slower as it nears its target.
Something like this:
Code:
//Create
startValue = 0;
targetValue = 100;
speedFactor = 0.2;

//Step
startValue += speedFactor * (targetValue - startValue);

//Or alternatively like this:
startValue = lerp(startValue, targetValue, speedFactor);
 

samspade

Member
I'm asking lerp function analogues that works perfectly.
I'm not sure I understand. lerp does work perfectly. It does exactly what it is supposed to every time. If you're getting unexpected results then there is something in your code, which is why you should post it.

If you like how that looks but want something similar, look up easing and tweening. Those all function like lerp, they interpolate between one number and another, but the difference is in how they interpolate. There are several free tweening assets available in the marketplace as well.
 
Top