tiny_plane.gd 815 B

1234567891011121314151617181920212223242526272829303132333435
  1. class_name TinyPlane
  2. extends RigidBody3D
  3. @export var thrust_power: float = 14000.0
  4. @export var turn_to_torque: float = 2000.0
  5. @export var move_to_pitch: float = 2000.0
  6. var target_torque: float = 0.0
  7. var target_pitch: float = 0.0
  8. var target_rotation := Vector3.ZERO
  9. var target_thrust := Vector3.ZERO
  10. func trigger_thrust() -> void:
  11. target_thrust = Vector3.FORWARD * thrust_power
  12. func trigger_direction(dir: Vector2) -> void:
  13. print(dir)
  14. target_torque = -dir.x * turn_to_torque
  15. target_pitch = -dir.y * move_to_pitch
  16. func _physics_process(delta: float) -> void:
  17. apply_torque(transform * Vector3(target_pitch, 0.0, target_torque))
  18. apply_central_force(target_thrust)
  19. func _on_dir_changed(dir: Vector2) -> void:
  20. trigger_direction(dir)
  21. func _on_main_action() -> void:
  22. print("Thrust !")
  23. trigger_thrust()