turn player to direction of moviment

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

How do i turn my 3d player direction to the moviment pressed?
I tried many ways but did not work. Here is the code.

extends KinematicBody

var accel = 5
var speed = 10
var velocity = Vector3()

var direction = Vector3()
var mouse_sens = 0.1
onready var pivot = $pivot

func _ready():
pass

func _input(event):
if event is InputEventMouseMotion:
rotate_y(deg2rad(-event.relative.x * mouse_sens))
pivot.rotate_x(deg2rad(-event.relative.y * mouse_sens))
pivot.rotation.x = clamp(pivot.rotation.x, deg2rad(-90), deg2rad(90))

func _process(delta):
var is_moving = false
direction = Vector3()

if Input.is_action_pressed("ui_up"):
	direction -= transform.basis.z
	
elif Input.is_action_pressed("ui_down"):
	direction += transform.basis.z
	
if Input.is_action_pressed("ui_left"):
	direction -= transform.basis.x
	is_moving = true
	
elif Input.is_action_pressed("ui_right"):
	direction += transform.basis.x
	is_moving = true
direction = direction.normalized()
velocity = direction * speed
velocity.linear_interpolate(velocity, accel * delta)
move_and_slide(velocity, Vector3.UP)

This question has already been answered here

Afely | 2020-10-30 03:10

I dont want 2d ‘-’

jm4rcos | 2020-11-01 15:18