Whats the error in my code?

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

func _ready():
	# Called every time the node is added to the scene.
	# Initialization here
	set_process(true);
	
func _process(delta):
	if Input.is_action_pressed("a"):
		var rota = rad2deg(get_node(".").get_rotation().y);
		rota = rota + 5;
		get_node(".").set_rotation(Vector3(0, deg2rad(rota), 0));
	if Input.is_action_pressed("d"):
		var rotd = rad2deg(get_node(".").get_rotation().y);
		var srotd = rotd - 5;
		get_node(".").set_rotation(Vector3(0, deg2rad(srotd), 0));
	if Input.is_action_pressed("w"):
		var rotw = rad2deg(get_node(".").get_rotation().x);
		rotw = rotw + 5;
		get_node(".").set_rotation(Vector3(deg2rad(rotw), 0 , 0));
	if Input.is_action_pressed("s"):
		var rots = rad2deg(get_node(".").get_rotation().x);
		rots = rots - 5;
		get_node(".").set_rotation(Vector3(deg2rad(rots), 0, 0));
	pass

When I execute it, it, works fine, but using d or a key after using w or s, resets the view. For example, when I use d key to change the view to 45 degree, and use w key to move up, the view gets reset

Link here Link to the pastebin

abhaskumarsinha | 2017-10-02 06:20

:bust_in_silhouette: Reply From: volzhs

set_rotation() performs setting rotation absolute value.
if you want to rotate it incrementally, use rotate() or rotate_x() / rotate_y() / rotate_z()

Does’t works… Please can you give me the full code?

abhaskumarsinha | 2017-10-02 11:24

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))

volzhs | 2017-10-02 11:26

Please, can I know how you are so fast, I just came from fridge, and when I refreshed the page, the whole code was written and posted…

abhaskumarsinha | 2017-10-02 11:27

that is a secret… :slight_smile:

volzhs | 2017-10-02 11:32

please :slight_smile: Tell me, I need this :slight_smile:

abhaskumarsinha | 2017-10-02 11:33

You can mail me your secret in abhaskumarsinha@gmail.com

abhaskumarsinha | 2017-10-02 11:34

Just a little note: It would be better to multiply the rotation constant by the delta time. This would make the animation more similar across different machines. Something like rotate_y(deg2rad(5) * delta) but probably with a bit larger constant (as the constant is rotation speed now instead of the rotation amount itself).

Tegu | 2017-10-02 18:06