jeep.gd 975 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 _ready() -> void:
  7. hand_brake(true)
  8. func steer(ratio: float) -> void:
  9. set_steering(ratio * max_steering)
  10. func hand_brake(enabled: bool) -> void:
  11. if enabled:
  12. set_brake(max_brake_force)
  13. else:
  14. set_brake(0.0)
  15. func get_free_seat() -> Node3D:
  16. return %RearSeat
  17. func drive_with(commander: LocalInput) -> void:
  18. hand_brake(false)
  19. super.drive_with(commander)
  20. func get_out() -> void:
  21. hand_brake(true)
  22. super.get_out()
  23. func _on_dir_changed(dir: Vector2) -> void:
  24. steer(-dir.x)
  25. func _on_main_action(pressed: bool) -> void:
  26. if pressed:
  27. set_engine_force(max_engine_force)
  28. else:
  29. set_engine_force(0.0)
  30. func _on_stop_action(pressed: bool) -> void:
  31. hand_brake(pressed)
  32. func _on_analog_action(side: int, value: float) -> void:
  33. set_engine_force(side * value * max_engine_force)