A
Alessio
Guest
Hi. This is more a math question, since, even if i googled countless times this without even finding a proper explanation.
In games like Super Mario World, you can see Mario's running/walking animation speed is almost perfectly synchronized with his running speed. Same with his variable jump height: the faster he runs, the higher he jumps.
Now, a not bad but rather long way to do it is setting that speed with multiple condition, in this way:
You may try the same with the jump height. Note that a friction/acceleration system is used so the character's movements are smooth like in a Mario game and not rigid like in a SEGA Mickey Mouse one.
Now, this may work but i'm pretty sure there is a more accurate way to do this.
I know about the "lerp" that returns an inbetween value between other two values based on a given interpolation amount. For example, in a horizontal speed value between 5 and 10, a percentage of 0.5 would make the lerp function return a value of 7.5. Same with a jump height value between 7 and 12, it would return 8.5. This is why the lerp function used between two objects' x coordinate causes a smooth camera movement (unless the percentage is 1, which would return the maximum value, or 0, where the minimum is returned and, therefore, the camera will not move at all).
Now i just would like to know how would you change that percentage value depending from the horizontal speed. I mean, we have this horizontal speed that has a minimum of 5 and a max of 10 and a percentage that has a minimum of 0 and a maximum of 1: those can't decrease beyond their minimum and viceversa. When the speed increases towards its maximum, also the percentage does towards 1 and viceversa. A graphical representation of what i mean:
5<->6.0<->7.0<->8.0<->9.0<->10 = Horizontal Speed
0<->0.2<->0.4<->0.6<->0.8<->1 = Percentage
... you get the idea, i hope. That percentage will be used as an interpolation value for the jump height and image speed variables, naturally so every one of these variables will be synchronized with the horizontal speed.
What are practical ways to do it? How do you make the percentage depend from the horizontal speed?
In games like Super Mario World, you can see Mario's running/walking animation speed is almost perfectly synchronized with his running speed. Same with his variable jump height: the faster he runs, the higher he jumps.
Now, a not bad but rather long way to do it is setting that speed with multiple condition, in this way:
Code:
if hspeed >= 2 then image_speed = 1
if hspeed >= 3 then image_speed = 1.3
if hspeed >= 4 then image_speed = 1.6
if hspeed >= 5 then image_speed = 1.9
Now, this may work but i'm pretty sure there is a more accurate way to do this.
I know about the "lerp" that returns an inbetween value between other two values based on a given interpolation amount. For example, in a horizontal speed value between 5 and 10, a percentage of 0.5 would make the lerp function return a value of 7.5. Same with a jump height value between 7 and 12, it would return 8.5. This is why the lerp function used between two objects' x coordinate causes a smooth camera movement (unless the percentage is 1, which would return the maximum value, or 0, where the minimum is returned and, therefore, the camera will not move at all).
Now i just would like to know how would you change that percentage value depending from the horizontal speed. I mean, we have this horizontal speed that has a minimum of 5 and a max of 10 and a percentage that has a minimum of 0 and a maximum of 1: those can't decrease beyond their minimum and viceversa. When the speed increases towards its maximum, also the percentage does towards 1 and viceversa. A graphical representation of what i mean:
5<->6.0<->7.0<->8.0<->9.0<->10 = Horizontal Speed
0<->0.2<->0.4<->0.6<->0.8<->1 = Percentage
... you get the idea, i hope. That percentage will be used as an interpolation value for the jump height and image speed variables, naturally so every one of these variables will be synchronized with the horizontal speed.
What are practical ways to do it? How do you make the percentage depend from the horizontal speed?