jeep.gd 873 B

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