This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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.isactionpressed("ui_up"):

moveAcl += 0.01
velocity = Vector2(1, 0).rotated(rotation)

if not Input.isactionpressed("ui_up") and moveAcl > 0:

moveAcl -= 0.02

velocity = moveandslide(velocity * moveAcl * 100)

Godot version latest
in Engine by (81 points)

1 Answer

0 votes

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)
by (3,328 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.