jeep.gd 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 get_door() -> Node3D:
  18. return %RightDoor
  19. func get_closest_door(from: Vector3) -> Node3D:
  20. return get_door()
  21. func drive_with(commander: LocalInput) -> void:
  22. hand_brake(false)
  23. super.drive_with(commander)
  24. func get_out() -> void:
  25. hand_brake(true)
  26. super.get_out()
  27. func _on_dir_changed(dir: Vector2) -> void:
  28. steer(-dir.x)
  29. func _on_main_action(pressed: bool) -> void:
  30. if pressed:
  31. set_engine_force(max_engine_force)
  32. else:
  33. set_engine_force(0.0)
  34. func _on_stop_action(pressed: bool) -> void:
  35. hand_brake(pressed)
  36. func _on_analog_action(side: int, value: float) -> void:
  37. set_engine_force(side * value * max_engine_force)