33 lines
933 B
GDScript
33 lines
933 B
GDScript
extends Thruster
|
|
|
|
@export var thruster_strength := 40.0
|
|
@export var rotation_strength := 10.0
|
|
@export var drift_curve : Curve
|
|
|
|
@onready var pushback: Area2D = $pushback
|
|
var active: bool = false
|
|
var rotating: float
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
if player == null:
|
|
return
|
|
|
|
if active:
|
|
%fire.emitting = true
|
|
%smoke.emitting = true
|
|
pushback.gravity = -1500.0
|
|
var angle = abs(player.linear_velocity.angle_to(Vector2.UP.rotated(player.rotation)))
|
|
var drift_factor = 2.0 * drift_curve.sample_baked(angle / PI) + 1.0
|
|
player.apply_central_impulse(Vector2.UP.rotated(player.rotation) * thruster_strength * delta * drift_factor)
|
|
else:
|
|
%fire.emitting = false
|
|
%smoke.emitting = false
|
|
pushback.gravity = 0
|
|
player.parts.angular_velocity_target = rotating * rotation_strength
|
|
|
|
func update_vector(input: Vector2) -> void:
|
|
active = input.y > 0
|
|
rotating = input.x
|
|
|
|
func is_thrusting() -> bool:
|
|
return active
|