0 votes
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

asked Oct 2, 2017 in Engine by abhaskumarsinha (63 points)
edited Oct 2, 2017 by volzhs

1 Answer

0 votes
Best answer

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

answered Oct 2, 2017 by volzhs (9,086 points)
selected Oct 2, 2017 by abhaskumarsinha

Does't works.... Please can you give me the full code?

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

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

that is a secret... :)

please :) Tell me, I need this :)

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

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

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.