I'd like to know what's wrong with this code.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DevJElly

(The content may be awkward because I use a translator.)
Hello
I use the touchscreen.
I want to be able to move my character.
So with someone else’s help,
I’ve written the code.
We also connected touchscreen nodes to the kinematic body.
(pressured and released)
But it didn’t work.
I want to know what went wrong in this code.
Help me.

extends KinematicBody2D

var velocity = Vector2()

func _on_up_pressed():
velocity.y -= 1

func _on_up_released():
velocity.y -= 1

func _on_down_pressed():
velocity.y += 1

func _on_down_released():
velocity.y += 1

func _on_right_pressed():
velocity.x += 1

func _on_right_released():
velocity.x += 1

func _on_left_pressed():
velocity.x -= 1

func _on_left_released():
velocity.x -= 1
(The touchscreen is also enabled with the mouse.)

:bust_in_silhouette: Reply From: Schweini

You still have to write move_and_slide, this also should be handled different.
Look at: https://www.youtube.com/watch?v=gylnwemFIZc

Thank you so much

DevJElly | 2020-07-27 10:08