I'm trying to build an arcade flying game, but I'm having difficulties understanding and applying rotation, when my camera is not static.

Basically, I have a scene composed of:

Kinematic Body
- MeshInstance
- CollisionShape
- Camera

And the following code on the KinematicBody:

extends KinematicBody
var pitch_input:float = 0.0
var roll_input:float = 0.0
var pitch:float = 0.0
var yaw:float = 0.0
var roll:float = 0.0
var _velocity
var Pitch
var Roll

func get_input(_delta):
# pitch, assigned to controler axis or buttons
pitch_input =  Input.get_action_strength("pitch_up") - Input.get_action_strength("pitch_down")

# roll
roll_input = Input.get_action_strength("roll_left") - Input.get_action_strength("roll_right")

func _physics_process(delta: float) -> void:
get_input(delta)

pitch = pitch + pitch_input * .1
roll = roll + roll_input * .1

transform.basis = Basis()
rotate_object_local(Vector3(1,0,0), pitch)
rotate_object_local(Vector3(0,0,1), roll)

transform = transform.orthonormalized()

_velocity = -transform.basis.xform(Vector3(0, 0, 0))
_velocity = move_and_slide(_velocity, Vector3.UP)

I expected that "rotateobjectlocal" would rotate the object aroung its local x and z axis, as if I was rotating them in the inspector using the local space. But what happes is that the axis are dependent on the pointing direction of the camera.

Its also weird to me that if the camera is static and not a child of the KinematicBody, everything works IF I use:

rotate_object_local(Vector3(1,0,0), pitch)
rotate(Vector3(0,0,1), roll)

I also tryed rotating around the camera basis, but it did not work the way I tried:

rotate_object_local(\$Camera.transform.basis.z, roll)

I also tried to put things in gimbals, like:

Roll
--Pitch
---KinematicBody
---- ...

And rotating the Roll and the Pitch, but results were basically the same.

Also, I can kind of get the result I expect using RigidBody, but all the rest of the things I want to do would be much harder (I think).

If anybody could shed some light, I would really appreciate. Living is easy, 3D math is hard.

edited Jun 12