# rotate 3d character on Y.axis

Attention Topic was automatically imported from the old Question2Answer platform.

I have movement figured out with wasd keys but now I need my character to face direction of travel, the camera is a child of character in a top down view and the camera is fine how it is. please help, I honestly thought there would be more tutorials on this Diablo 3/ pokemon lets go style of movement but all i find is snippets of chopped up information. I’ve been playing around with Transform.basis a bit but get so close only to be missing crucial parts of the script. Please help

On the `Spatial` node (or whichever node) which has to be rotated, have you tried something like `node.basis.rotated( Vector3(0, 1, 0), phi)`, where “phi” is by how much you want the node turned? I found the function here, btw.

Ertain | 2020-03-16 23:41

I’m trying to use my camera coordinates as a reference to transform my characters direction if i can’t get it to work , i’ll try using phi method you mentioned above. cheers

markelliot_94 | 2020-03-17 05:18

I got it to work, via camera basis, *crying in joy, spent the last week trying to figure that out, I need to put out a video for people trying the same thing, thanks for the reply though everything helps. this stuff aint easy for Newbs.

markelliot_94 | 2020-03-17 05:35

I was trying to do something similar. But I got stuck on the `move_and_slide()` function.

Ertain | 2020-03-17 20:13

probs a simpler way of doing it but this is what i have.

extends KinematicBody

var gravity = -10
var velocity = Vector3()
var camera
var character
const SPEED = 8
const ACCELERATION = 15
const DE_ACCELERATION = 15

``````camera = get_node("Camera").get_global_transform()
character = get_node("Sam000")
``````

func _physics_process(delta):

``````var dir = Vector3()
var is_moving = false

if Input.is_action_pressed("forward"):
dir += -camera.basis[2]
is_moving = true
if Input.is_action_pressed("backward"):
dir += camera.basis[2]
is_moving = true
if Input.is_action_pressed("left"):
dir += -camera.basis[0]
is_moving = true
if Input.is_action_pressed("right"):
dir += camera.basis[0]
is_moving = true

dir.y = 0
dir = dir.normalized()
velocity.y += delta * gravity
var hv = velocity
hv.y = 0

var new_pos = dir * SPEED
var accel = DE_ACCELERATION

if (dir.dot(hv) > 0):
accel = ACCELERATION
hv = hv.linear_interpolate(new_pos,accel*delta)
velocity.x = hv.x
velocity.z = hv.z

if is_moving:
var angle = atan2(hv.x,hv.z)
var char_rot = character.get_rotation()
char_rot .y = angle
character.set_rotation(char_rot)
var speed = hv.length() /SPEED
velocity = move_and_slide(velocity,Vector3.UP)
``````

markelliot_94 | 2020-03-19 15:57