0 votes

I've wrote a code for camera in GDscript which will help the user to view their models in all paranoma.

Code Link --> https://pastebin.com/HvKKSwn9 <-- what is the error in the code.

code attached from link

extends Spatial

func _ready():
    var x;
    var y;
    var mouse_sensitivity;

    set_process_input(true);

    # set the mouse sensitivity of the mouse
    var view_sen = 0.2
    Input.set_mouse_mode(2);
func _input(ie):

    #get present rotation of the scene node
    var x = rad2deg(get_node(".").get_rotation().x);
    var y = rad2deg(get_node(".").get_rotation().y);

    #now get the rotation of the mouse, with mouse x and mouse y
    var x = fmod(x - ie.relative_x * 0.2, 360);
    var y = fmod(y - ie.relative_y * 0.2, 90);

    #now just set the values
    get_node(".").set_rotation(Vector3(deg2rad(x), 0, 0));
    get_node(".").set_rotation(Vector3(0, deg2rad(y), 0));

    print ("" , x);
    print ("" , y);

The y axis motion of the mouse is not working.

asked Sep 5, 2017 in Engine by abhaskumarsinha (63 points)
edited Sep 5, 2017 by volzhs

1 Answer

0 votes

The second call to set_rotation is erasing the previous call, set both values in one call or even better use a matrix to make the transformations.

answered Sep 5, 2017 by davidoc (384 points)

How to do that? Seems impossible, I'm a noob in coding? Why it erases the first call?

changing does't works

get_node(".").set_rotation(Vector3(deg2rad(x), Vector3(0, deg2rad(y)), 0));

It does't works, says nonexistant constructor.

Sorry, even after correcting the code, the y axis moves instead of x and it rotates digonally instead of y axis rotation.

get_node(".").set_rotation(Vector3(deg2rad(x), deg2rad(y), 0));

As I mentioned you should use a matrix and call set_transformation because you can have a Gimbal lock.

how to use matrix? what is set_transformation? and what is Gimbal Lock?

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.