vehicle.gd 834 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. extends VehicleBody
  2. # Member variables
  3. const STEER_SPEED = 1
  4. const STEER_LIMIT = 0.4
  5. var steer_angle = 0
  6. var steer_target = 0
  7. export var engine_force_value = 40
  8. func _physics_process(delta):
  9. if Input.is_action_pressed("ui_left"):
  10. steer_target = STEER_LIMIT
  11. elif Input.is_action_pressed("ui_right"):
  12. steer_target = -STEER_LIMIT
  13. else:
  14. steer_target = 0
  15. if Input.is_action_pressed("ui_up"):
  16. engine_force = engine_force_value
  17. else:
  18. engine_force = 0
  19. if Input.is_action_pressed("ui_down"):
  20. brake = 1
  21. else:
  22. brake = 0.0
  23. if steer_target < steer_angle:
  24. steer_angle -= STEER_SPEED * delta
  25. if steer_target > steer_angle:
  26. steer_angle = steer_target
  27. elif steer_target > steer_angle:
  28. steer_angle += STEER_SPEED * delta
  29. if steer_target < steer_angle:
  30. steer_angle = steer_target
  31. steering = steer_angle