jeep.gd 848 B

12345678910111213141516171819202122232425262728293031323334353637
  1. extends VehicleBody3D
  2. @onready var max_engine_force: float = 500
  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 get_free_seat() -> Node3D:
  16. return %RearSeat
  17. func _on_dir_changed(dir: Vector2) -> void:
  18. steer(-dir.x)
  19. func _on_main_action(pressed: bool) -> void:
  20. if pressed:
  21. set_engine_force(max_engine_force)
  22. else:
  23. set_engine_force(0.0)