player.gd 640 B

1234567891011121314151617181920212223
  1. extends Sprite2D
  2. @export var speed : float = 100
  3. @export var joystick_left : VirtualJoystick
  4. @export var joystick_right : VirtualJoystick
  5. var move_vector := Vector2.ZERO
  6. func _process(delta: float) -> void:
  7. ## Movement using the joystick output:
  8. # if joystick_left and joystick_left.is_pressed:
  9. # position += joystick_left.output * speed * delta
  10. ## Movement using Input functions:
  11. move_vector = Vector2.ZERO
  12. move_vector = Input.get_vector("ui_left","ui_right","ui_up","ui_down")
  13. position += move_vector * speed * delta
  14. # Rotation:
  15. if joystick_right and joystick_right.is_pressed:
  16. rotation = joystick_right.output.angle()