How to disable Gimbal lock?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By abhaskumarsinha
:warning: Old Version Published before Godot 3 was released.
func _process(delta):
if Input.is_action_pressed("a"):
if Input.is_action_pressed("d"):
if Input.is_action_pressed("w"):
if Input.is_action_pressed("s"):

Having problems with Gimbal Lock, how to fix that?

When I rotate myself to upwards 45 degree and sideways 45 degrees, then I the camera also rotates, I want to fix it, so that camera does’t rotate on its view axis.

I am unsure if I understand fully where your problem is.

Is the camera a child of a Kinetic/RigidBody ?
Then it will rotate with the movement of the body.

You could move the camera out of that body and adjust its position/angle separately.

Something like this (untested) inside the camera node:

extends Camera

var body

const CAMDIST = 20

func _ready():
	body=get_node("../Body") #init with position of body (edit to adjust node name/path)
func _fixed_process(delta):
	var bt=body.get_transform()
	var ct=get_transform()
    var lookdir = bt.basis.z #get rotated z-vector of body
    lookdir.y = 0 #don't look up/down
	ct.origin=bt.origin #camera position = body position
	ct = ct.looking_at(lookdir,Vector3(0,1,0))

wombatstampede | 2017-10-04 10:59