# How can I rotate 3d player movement in relation to camera rotation?

4.3

### Question

I’m trying to make a Starfox like game and I coded player movement and made it feel solid. But then I wanted to put the player scene on a pathfollow3d so that I can edit the way the ship flies through the level. This is where I realized my problem.
In my player scene I have a “player” node3d with a “ship” characterbody3d as a child and also the camera3d as a child. I coded the player so that left and right are on the X axis and up and down is on the Y axis. The problem with this is that when the entire player scene follows the path3d I would like it to rotate on the X and Y axis to increase immersion of flying through the level. As an example, when the entire player scene rotates 90 degrees on the Y axis to follow the path, the ship is still moving “left” and “right” on the X axis. But with the rotated camera angle it now looks like the ship is moving towards and away from the camera. I have the same problem when the entire player rotates on the X axis, when moving the ship “up” and “down” the angle is completely wrong.
In summary, how can I make it so no matter what direction or what angle the camera is looking when the ship moves right, left, up, down they are still moving right, left, up, down in relation to the screen.

I’ve stripped down my movement code to the bare minimum to try to solve this problem and here’s what I have.

``````extends CharacterBody3D

const SPEED = 25.0

func _physics_process(delta):
var input_dir = Input.get_vector("right", "left", "down", "up")
var direction = (transform.basis * Vector3(input_dir.x, input_dir.y, 0))
if direction:
velocity.x = direction.x * SPEED
velocity.y = direction.y * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.y = move_toward(velocity.y, 0, SPEED)

move_and_slide()

``````