The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes
func _process(delta):
if Input.is_action_pressed("a"):
    get_node(".").rotate_y(deg2rad(5))
if Input.is_action_pressed("d"):
    get_node(".").rotate_y(deg2rad(-5))
if Input.is_action_pressed("w"):
    get_node(".").rotate_x(deg2rad(5))
if Input.is_action_pressed("s"):
    get_node(".").rotate_x(deg2rad(-5))

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.

in Engine by (65 points)

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)
    set_fixed_process(true)

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))
    set_transform(ct)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.