K
Kamon145
Guest
Hello everyone! I am currently working on a platformer and my player has a maximum run speed that i would like to keep them from going over, but other objects in the game (such as explosions, ect) should still be able to add speed, my current code as it stands is
hinput returns either 1 or -1 depending on direction pressed,
this works for keeping the player from going over speed, but prevents additional speed from being added, i have tried something along the lines of adding a check at the beginning
but this dosent work because i assume the exact value of spd_max is being skipped over, and I've tried using <= and >= and they both work, but only in one direction, is there a function to check if a number has gone past a value? like "if spd[h] is between -run_spd, and run_spd"?
Code:
spd[h] +=hinput*accel//add acceleration to speed either positive or negative depending on value returned
spd[h] = clamp(spd[h],-spd_max,spd_max)
x+=spd[h]
this works for keeping the player from going over speed, but prevents additional speed from being added, i have tried something along the lines of adding a check at the beginning
Code:
if spd[h] != hinput*run_spd
spd[h] +=hinput*accel//add acceleration to speed either positive or negative depending on value returned
spd[h] = clamp(spd[h],-spd_max,spd_max)