Godot Version
4.3
Question
Trying to make friction apply when my character stops walking or running and I want to see if there is anyway to apply the friction to the speed and if there is anyway to apply it with lerp?
4.3
Trying to make friction apply when my character stops walking or running and I want to see if there is anyway to apply the friction to the speed and if there is anyway to apply it with lerp?
I’d recommend move_toward
instead of lerp
. What does your script look like so far? What have you tried?
The way I originally tried doing my friction was based on velocity but since I don’t want to have acceleration I couldn’t find out a way to make it work out
And I’m trying to find a way where if my state is equal to idle friction apply’s to the character based on there speed at the time
my walk and run are base upon a variable that updates called current_speed which tracks the global speed and how it changes
func run(direction, current_speed, run_speed):
if disableRun:
default_walk(direction, current_speed)
return
else:
if direction:
velocity.x = direction * current_speed * run_speed
else:
velocity.x = move_toward(velocity.x, 0, current_speed * run_speed)
func default_walk(direction, current_speed):
if direction != 0:
velocity.x = direction * current_speed
else:
velocity.x = move_toward(velocity.x, 0, current_speed * friction)
The code under the walk was me trying to apply friction but Im still confused on how to
So your current_speed
is in pixels per second, your run_speed
is a multiplier (maybe 2), what is friction
?
I’m guessing by friction you mean your character stops instantly and you want a more gradual stop?
I don’t see delta
in any of these functions, but you will need it for other pixel per second units like friction
should be.
Try making this line, with friction
being greater than current_speed
, for reference if it’s twice as much as current_speed
then your character will slow down after half a second. If it’s four times as much it slow in a quarter of a second.
velocity.x = move_toward(velocity.x, 0, friction * delta)
Will try out and yes my run_speed is a multiplier, and you are correct that im trying to make more of a gradual stop, Thank You So much