Attention | Topic was automatically imported from the old Question2Answer platform. | |
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)