What is the error in my code for 3D games?

: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.

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

Code Link → Godot error - Pastebin.com ← 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.

:bust_in_silhouette: Reply From: davidoc

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.

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

abhaskumarsinha | 2017-09-07 13:27

changing does’t works

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

It does’t works, says nonexistant constructor.

abhaskumarsinha | 2017-09-07 13:33

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

abhaskumarsinha | 2017-09-07 13:41

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.

davidoc | 2017-09-07 13:48

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

abhaskumarsinha | 2017-09-07 16:55