0 votes
var MOUSE_SENSITIVITY = 0.005
var rot_x = 0
var rot_x_target = 0

var rot_y = 0
var rot_y_target = 0

var rot_z = 0
var rot_z_target = 0   

func _process(delta):
        transform.basis = Basis()

        rot_x_target = lerp(rot_x_target,rot_x,0.05)
        rot_y_target = lerp(rot_y_target,rot_y,0.05)
        rot_z_target = lerp(rot_z_target,rot_z,0.05)

        rotate_object_local(Vector3(0, 1, 0), rot_x_target)
        rotate_object_local(Vector3(1, 0, 0), rot_y_target)

        if Input.is_key_pressed(KEY_E):
            rot_z -= .01
        if Input.is_key_pressed(KEY_Q):
            rot_z += .01
        rotate_object_local(Vector3(0, 0, 1), rot_z_target)

func _ready():
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _input(event):
        if event is InputEventMouseMotion:
            rot_x -= (event.relative.x * MOUSE_SENSITIVITY )
            rot_y -= (event.relative.y * MOUSE_SENSITIVITY )

everything is working as intended until I press Q or E which results in the object rotating along the Z axis(as intended) but the issue here is that if I rotate along the X and Y axis they don't rotate along the new Z axis.
you can slap this code on a camera node and see for yourself what I mean
any help would be very much appreciated!

Godot version 3.2.3
in Engine by (26 points)

1 Answer

0 votes

I'm not entirely sure about what you're trying to do exactly. I think I've managed to get the result your expecting by simply changing

rotate_object_local(Vector3(0, 0, 1), rot_z_target)

to

rotate_z(rot_z_target)
by (615 points)

This only fixes the issue in two directions(Forward and back) since rotate_z will cause the object to rotate around the global Z axis, I need it to basically behave like this but in any give direction not just forward and backwards.

https://imgur.com/a/2Z2WJyh
Between slides 2 and 3 its the same object just rotated 90 degrees right]

as you can see it doesnt rotated as needed, I think you need to somehow set a new z basis every z rotation or something in the lines of that but I cant get it to work..

rotate_object_local(Vector3(0, 0, 1), rot_z_target)

^this fixes this issue but it doesnt fix the main issue where for example i rotate 90 degrees on the X(move the mouse left) axis and the 90 degrees on the Z axis(press E) but if I move the mouse up in that position the object will rotate UP in the global direction and if I move the mouse left it moves left in the global position which isnt what I want

I still very much appreciate your help!

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 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 webmaster@godotengine.org with your username.