local_input.gd 629 B

12345678910111213141516
  1. class_name LocalInput
  2. extends Node
  3. # Sends commands from a local device
  4. signal dir_changed(new_dir: Vector2)
  5. signal main_action(pressed: bool)
  6. signal get_in_action(commander: LocalInput)
  7. func _unhandled_input(event: InputEvent) -> void:
  8. if event.is_action("main"):
  9. main_action.emit(event.is_pressed())
  10. elif event.is_action_pressed("get_in"):
  11. get_in_action.emit(self)
  12. elif event.is_action("move_left") or event.is_action("move_right") or event.is_action("move_back") or event.is_action("move_forward"):
  13. var dir: Vector2 = Input.get_vector("move_left", "move_right", "move_back", "move_forward")
  14. dir_changed.emit(dir)