Godot 4.4
I was trying to make fpv drone, but my script don’t want to work. Can you fix it pls?
extends RigidBody3D
@export var thrust_force: float = 50.0
@export var rotation_speed: float = 5.0
@export var stabilization_speed: float = 2.0
@export var camera_pivot: Node3D
@export var propeller_sound: AudioStreamPlayer3D
var current_thrust := 0.0
func _physics_process(delta: float) → void:
handle_input(delta)
stabilize(delta)
func handle_input(delta: float) → void:
var thrust_input = Input.get_axis(“s”, “w”)
current_thrust = lerp(current_thrust, thrust_input * thrust_force, delta * 5.0)
apply_central_force(Vector3.UP * current_thrust)
var rotation_input = Vector3(
Input.get_axis(“ui_down”, “ui_up”),
Input.get_axis(“q”, “e”),
Input.get_axis(“a”, “d”)
)
apply_torque(rotation_input * rotation_speed)
func stabilize(delta: float) → void:
var current_rotation = rotation
var target_rotation = Vector3(0, current_rotation.y, 0)
rotation = rotation.lerp(target_rotation, stabilization_speed * delta)