Problem in turning the kinematic body full 90 degrees with mouse inputs.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Dinoking

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)
:bust_in_silhouette: Reply From: mburkard

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)

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

Dinoking | 2020-12-23 16:55

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

mburkard | 2020-12-23 17:16

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.

Dinoking | 2020-12-23 17:24