tiny_plane.gd 862 B

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