0 votes

I am trying to rotate the player by code to correct angle pressing a key.

    if Input.is_action_pressed("ui_right"):
    rotation_dir += 1
if Input.is_action_pressed("ui_left"):
    rotation_dir -= 1
if Input.is_action_pressed("ui_down"):
    velocity += -transform.basis.z * speed
if Input.is_action_pressed("ui_up"):
    velocity += transform.basis.z * speed

    #rotate the player  in 0,90,-90,180

if Input.is_key_pressed(KEY_M):
    if rotation_degrees.y>0 and rotation_degrees.y<90:
    if rotation_degrees.y>90 and rotation_degrees.y<180:
    if rotation_degrees.y>-180 and rotation_degrees.y<-90:
    if rotation_degrees.y>-1 and rotation_degrees.y>-90:
rotation.y += rotation_dir * speed * delta
velocity = move_and_slide(velocity)
Godot version 3.4.3
in Engine by (21 points)

1 Answer

0 votes

You could calculate the rotation degrees based on the player's movement direction.
Take a look at the Godot Docs:

by (1,075 points)
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.