0 votes
extends Camera

func _ready():
    # Called every time the node is added to the scene.
    # Initialization here

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

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

in Engine by (65 points)
edited by

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

by (9,712 points)
selected by

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

func _process(delta):
    if Input.is_action_pressed("a"):
    if Input.is_action_pressed("d"):
    if Input.is_action_pressed("w"):
    if Input.is_action_pressed("s"):

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.
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 webmaster@godotengine.org with your username.