ship.gd 515 B

123456789101112131415161718192021222324
  1. class_name Ship
  2. extends RigidBody2D
  3. # Common base script for ships
  4. const THRUST_STRENGTH = 400_000
  5. const TORQUE_THRUST = 1
  6. var current_force := Vector2.ZERO
  7. var current_torque : float = 0.0
  8. func _physics_process(delta):
  9. apply_central_force(current_force.rotated(rotation))
  10. apply_torque(current_torque)
  11. func _on_command(dir: Vector2) -> void:
  12. _thrust(dir)
  13. func _thrust(dir: Vector2) -> void:
  14. current_force = Vector2.UP * dir.y * THRUST_STRENGTH
  15. current_torque = dir.x * TORQUE_THRUST * THRUST_STRENGTH