I want a ship player. This is basic movement but not working.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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

velocity = move_and_slide(velocity * moveAcl * 100)

:bust_in_silhouette: Reply From: Gluon

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)