Godot Version
4.5.1
Question
Hello,
New to Godot and GDScript, and have been trying to do a demo by making a 'drone' (a Box mesh) be able to strafe. However, it's not gone very well:
1) Whenever the drone's 'move_right'/'move_left' inputs are used, if the drone is pointing down, it'll move in the right direction but up/down away from the camera as well
2) Whenever the 'sprint' (ascend - using the same input from another scene) or 'descend' inputs are used and the camera + drone points down (I assume it's the same when facing up), it'll move to the right/left repectively and slowly ascend
3) 'move_forward'/'move_back' doesn't move in the direction the camera is pointing vertically - instead it travels at same height irregardless of camera pitch but in the right direction horizontally.
4) My 'battery' get_gravity() only moves it down very slowly, despite it doing it much more rapidly and correctly in another script for testing.
Code:
extends CharacterBody3D
#drone
@export var move_speed = 5
@export var battery = 100
#camera
@onready var FPV = $FPV
@onready var Chase = $Chase
var mouse_sensitivity = 0.02
var rot_x = 0
var rot_y = 0
var rot_z = 0
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
var hud = $FPV/DroneHUD
if hud:
hud.drone = self
func _physics_process(delta: float) → void:
velocity = Vector3.ZERO
#movement
if Input.is_action_pressed("move_forward"):
velocity += -transform.basis.z * move_speed
if Input.is_action_pressed("move_back"):
velocity += transform.basis.z * move_speed
if Input.is_action_pressed("move_right"):
velocity += transform.basis.x * move_speed
if Input.is_action_pressed("move_left"):
velocity += -transform.basis.x * move_speed
if Input.is_action_pressed("sprint"):
velocity += transform.basis.y * move_speed
if Input.is_action_pressed("descend"):
velocity += -transform.basis.y * move_speed
if velocity.length() > move_speed:
velocity = velocity.normalized() * move_speed
transform = transform.orthonormalized()
#battery
if is_on_floor():
if battery < 100:
battery += 1 * delta
else:
battery -= 1 * delta
if battery < 0:
battery = 0
velocity += get_gravity() * delta
if Input.is_action_pressed("exit"):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
move_and_slide()
func _input(event):
if event is InputEventMouseMotion:
rot_y += -event.screen_relative.x * mouse_sensitivity
rot_z += -event.screen_relative.y * mouse_sensitivity
rot_z = clamp(rot_z, -1.5, 1.5)
transform.basis = Basis()
rotate_object_local(Vector3.UP, rot_y)
rotate_object_local(Vector3.RIGHT, rot_x)
rotate_object_local(Vector3.FORWARD, rot_z)
if event.is_action_pressed("FPV"):
FPV.current = true
elif event.is_action_pressed("Chase"):
Chase.current = true
If anyone is able to help with these (or just general script stuff), it’d be greatly appreciated - I’ve spent far too long trying to fix the first 3 (and only breaking the camera rotation in return).


