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:
And the following code on the 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
# pitch, assigned to controler axis or buttons
pitch_input = Input.get_action_strength("pitch_up") - Input.get_action_strength("pitch_down")
roll_input = Input.get_action_strength("roll_left") - Input.get_action_strength("roll_right")
func _physics_process(delta: float) -> void:
pitch = pitch + pitch_input * .1
roll = roll + roll_input * .1
transform.basis = Basis()
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:
I also tryed rotating around the camera basis, but it did not work the way I tried:
I also tried to put things in gimbals, like:
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.