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 the mouse sensitivity of the mouse
    var view_sen = 0.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.

in Engine by (65 points)
edited by

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.

by (1,002 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 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.