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