![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Help me please |
Hi
I just want to ask that how can I make on screen controls for RPGs
I have four buttons (i.e. up, down, left, right and shoot). I don’t have any problem to shoot but I don’t know how will I make my player moveable by these buttons.
I am using this code to move my player
extends KinematicBody2D
export (int) var speed = 200
var velocity = Vector2()
func get_input():
velocity = Vector2()
if Input.is_action_pressed("ui_right"):
velocity.x += 1
if Input.is_action_pressed("ui_left"):
velocity.x -= 1
if Input.is_action_pressed("ui_down"):
velocity.y += 1
if Input.is_action_pressed("ui_up"):
velocity.y -= 1
velocity = velocity.normalized() * speed
func _physics_process(delta):
get_input()
velocity = move_and_slide(velocity)