jeep.gd 807 B

12345678910111213141516171819202122232425262728293031323334
  1. extends VehicleBody3D
  2. @onready var max_engine_force: float = 50
  3. @onready var max_steering: float = PI / 6.0 # degrees
  4. var _current_commander: LocalInput = null
  5. func steer(ratio: float) -> void:
  6. set_steering(ratio * max_steering)
  7. ## Make the vehicle responds to driver commands
  8. func drive_with(commander: LocalInput) -> void:
  9. commander.dir_changed.connect(_on_dir_changed)
  10. commander.main_action.connect(_on_main_action)
  11. _current_commander = commander
  12. func get_out() -> void:
  13. _current_commander.dir_changed.disconnect(_on_dir_changed)
  14. _current_commander.main_action.disconnect(_on_main_action)
  15. func _on_dir_changed(dir: Vector2) -> void:
  16. print(dir)
  17. steer(-dir.x)
  18. func _on_main_action(pressed: bool) -> void:
  19. if pressed:
  20. set_engine_force(max_engine_force)
  21. else:
  22. set_engine_force(0.0)