Topic was automatically imported from the old Question2Answer platform.
Asked By
Xicola
So this is my code. I wanna create a sprint, for example: when I press “shift”, the speed of walk double or something like a speed bonus. Like a “walk to run” mechanic.
It’s actually easy. You just increase the acceleration and the maximum speed values when you want to sprint and reduce them back to normal after the sprint. Or you can increase just the maximum speed and add a value to motion.x to increase it or just multiply motion.x with a factor like 2 to double it after this line.
motion.x = clamp(motion.x, -MAX_SPEED, MAX_SPEED)
This way:
motion.x *= 2
So, I’ve write this
if Input.is_action_pressed("sprint") and is_on_floor():
motion.x *= 2
But when I press “right” and “left” together, he goes crazy, the character go out from the map.
Xicola | 2021-06-07 13:03
you can create sprint like this, I have created it successfully :
My script for movement: