jeep.gd 932 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. class_name Jeep
  2. extends SeatedVehicle
  3. @export var max_engine_force: float = 500
  4. @export var max_brake_force: float = 50
  5. @export var max_steering: float = PI / 6.0 # degrees
  6. func steer(ratio: float) -> void:
  7. set_steering(ratio * max_steering)
  8. func hand_brake(enabled: bool) -> void:
  9. if enabled:
  10. set_brake(max_brake_force)
  11. else:
  12. set_brake(0.0)
  13. func get_free_seat() -> Node3D:
  14. return %RearSeat
  15. func drive_with(commander: LocalInput) -> void:
  16. hand_brake(false)
  17. super.drive_with(commander)
  18. func get_out() -> void:
  19. hand_brake(true)
  20. super.get_out()
  21. func _on_dir_changed(dir: Vector2) -> void:
  22. steer(-dir.x)
  23. func _on_main_action(pressed: bool) -> void:
  24. if pressed:
  25. set_engine_force(max_engine_force)
  26. else:
  27. set_engine_force(0.0)
  28. func _on_stop_action(pressed: bool) -> void:
  29. hand_brake(pressed)
  30. func _on_analog_action(side: int, value: float) -> void:
  31. set_engine_force(side * value * max_engine_force)