How to keep doing an action when something is held down

so i wanted to make it so that when the right arrow key is pressed it moves a sprite to the right, which works but it doesnt as i wanted it to, i wanted it to move smoothly, but it moves pretty jankily.

my code:

func _input(event)
if Input.is_action_pressed("Up"):
$".".position.y += 1
$Camera2D.position.y += 1

any help is really appreciated!

-Quinn <3

might this https://forum.godotengine.org/t/help-coding-rapid-fire/119838/4?u=samthead solution help you?

If you only want movement you can use the _process function instead of _input.

_process runs every frame, where _input only runs when an input is registered, such as pressing or releasing a key, resizing the window.

func _process(delta: float) -> void:
    if Input.is_action_pressed("Up"):
        self.position.y += 100 * delta

One pixel isn’t very fast so as an example I’ve increased it to 100 pixels per second. You should avoid using $"." instead either use self or nothing at all, the script will know position means self.position

1 Like

this works really well, thank you so so much!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.