Drone doesn't fly

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)

There are a few things that may cause issues.

  • Make sure the central force is applied relative to your local rotation.
  • Since FpV drones stop rotating when no Input is given you shouldn’t use physics based rotation (apply_torque). Just use the rotate method or change the local rotation based on your input.
  • The stabilize method should be only called if there is no input

I hope that solves your issues.

1 Like

The fpv drone is trying to flip forward when trying to take off