I'm struggling to understand 3D transforms in Godot. (I know, I know...)
I'm trying my best to implement an aircraft control script, and I've gotten myself into gimbal lock hell. My controls work pretty well until the Y direction decides to flip, and now my controls to pull up make the plane go down, etc...
I've read the godot 3D transform documentation, but I still find myself looking for an "Aha!" moment.
I figured a good way for me to learn would be to post what code I have and see how others would implement the movement code using transforms correctly.
Thanks for any help in advance.
extends Spatial
Declare member variables here. Examples:
var a = 2
var b = "text"
onready var camera = $Camera
const SPEED = 7
const ROTATE_SPEED = 1.25
const MIN = 0.9
var rx = 0
var ry = 0
var rz = 0
Called when the node enters the scene tree for the first time.
func _ready():
pass
Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
self.transform.basis = Basis()
if Input.is_action_pressed("movement_forward"):
ry -= 1
if Input.is_action_pressed("movement_backward"):
ry += 1
if Input.is_action_pressed("movement_left"):
rx += 1
if Input.is_action_pressed("movement_right"):
rx -= 1
if Input.is_action_pressed("rotate_left"):
rz += 1
if Input.is_action_pressed("rotate_right"):
rz -= 1
self.transform.orthonormalized()
self.rotate_z(deg2rad(rz))
self.rotate_x(deg2rad(ry))
self.rotate_y(deg2rad(rx))
self.transform.origin += -self.transform.basis.z * SPEED * delta
```