123456789101112131415161718192021222324 |
- class_name Ship
- extends RigidBody2D
- # Common base script for ships
- const THRUST_STRENGTH = 400_000
- const TORQUE_THRUST = 1
- var current_force := Vector2.ZERO
- var current_torque : float = 0.0
- func _physics_process(delta):
- apply_central_force(current_force.rotated(rotation))
- apply_torque(current_torque)
- func _on_command(dir: Vector2) -> void:
- _thrust(dir)
- func _thrust(dir: Vector2) -> void:
- current_force = Vector2.UP * dir.y * THRUST_STRENGTH
- current_torque = dir.x * TORQUE_THRUST * THRUST_STRENGTH
|