jeep.gd 889 B

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