0 votes

(The content may be awkward because I use a translator.)
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 onup_pressed():
velocity.y -= 1

func onup_released():
velocity.y -= 1

func ondown_pressed():
velocity.y += 1

func ondown_released():
velocity.y += 1

func onright_pressed():
velocity.x += 1

func onright_released():
velocity.x += 1

func onleft_pressed():
velocity.x -= 1

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

in Engine by (22 points)

1 Answer

+1 vote
Best answer

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

by (231 points)
selected by

Thank you so much

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.