Lunar/ship.gd
2025-06-27 16:39:28 +10:00

28 lines
848 B
GDScript

extends RigidBody2D
signal moved
@export var thrust_power : float = 1
@export var turn_power : float = 1
@export var particles_l : CPUParticles2D
@export var particles_r : CPUParticles2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _physics_process(delta: float) -> void:
var turning : float = Input.get_axis("turn_left","turn_right") * turn_power
var thrust : float = Input.get_action_strength("thrust") * thrust_power
particles_l.emitting = thrust != 0
particles_r.emitting = thrust != 0
if Input.is_action_just_pressed("thrust"):
moved.emit()
#pass
apply_torque(turning)
apply_force(Vector2(-thrust,-thrust) * transform.y )