Topic was automatically imported from the old Question2Answer platform.
Asked By
MemokingMH
It works while moving but it doesn’t work when I release the button. I want it to slowly stop instead of stopping instantly but have 0 ideas instead of this
Here is the code:
if Input.is_action_pressed(“ui_up”):
>moveAcl += 0.01
>velocity = Vector2(1, 0).rotated(rotation)
if not Input.is_action_pressed(“ui_up”) and moveAcl > 0:
>moveAcl -= 0.02
You could try something like this (you may need to play with the values). it adds a small amount up to a max when the button is pressed and adds it to the velocity and when the button is released slowly decreases it.
if Input.isactionpressed("ui_up"):
moveAcl += 0.01
if impetusAcl < 0.10:
impetusAcl += 0.01
velocity = Vector2(1, 0).rotated(rotation)
if not Input.isactionpressed("ui_up") and moveAcl > 0:
if impetusAcl > 0:
impetusAcl -= 0.01
moveAcl -= 0.02
totAcl = moveAcl + impetusAcl
velocity = moveandslide(velocity * totAcl * delta)