0 votes

I have a kinematic body and i control it with left and right mouse buttons respectively. What I intend is that when I press the left or right mouse button , the kinematic body should rotate 90 degrees in the direction of click (i.e left or right). The movement works well, but when I press the buttons, it rotates slant , (doesn't rotate 90 degrees on y axis), for whatever degrees i have set in rotate_y() function, it rotates in same degrees.
, slanting.

video for reference
code :

extends KinematicBody


var velocity = Vector3()
var delay = 1
onready var timer = $Timer
var delay_counter = 0

func _physics_process(delta):

    var angle = get_rotation().y   
    velocity = Vector3(sin(angle),0, cos(angle)) * 2


    if Input.is_action_just_pressed("left"):
        rotate_y(5)


    if Input.is_action_just_pressed("right"):
        rotate_y(-5)





    velocity = move_and_slide(velocity)
Godot version godot v.3.2.1
in Engine by (44 points)

1 Answer

+1 vote

Hey,

I think the problem is the numbers used to rotate.
Rotations in Godot are measured in radians rather than degrees. This easy to get tripped up on since when editing the transform of an object in the actual editor it does use degrees.

So a 90 degree rotation would be PI / 2 and a -90 degree rotation would PI * 1.5

Try this.

if Input.is_action_just_pressed("left"):
    rotate_y(PI / 2)

if Input.is_action_just_pressed("right"):
    rotate_y(PI * 1.5)
by (54 points)

Is PI the pi that we use in math (3.14)?

Yes, specifically the Godot PI constant seems to go out to the millionths place 3.141593

Wow, sure , I'll try this once I get back to office, but I am sure this should work out, as I was thinking the same on degrees and radians, but hey, thanks, I didn't know how to implement anything of it.

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.