Move the 3D player relative to camera in Godot 4?

There is a helpful guide here that implements a simple method for moving relative to the camera.

Somewhere in your code could be something like this:

var relativeDir = Vector3(inputDir.x, 0.0, inputDir.y).rotated(Vector3.UP, cameraBase.rotation.y)

The rotated(axis: Vector3, angle: float) function returns a vector that’s been rotated on the given axis by the amount of angle in radians.

This means your input vector, after being converted to a vector3, is now rotating along with your camera, but only on the y axis. Vertically rotating the camera will no longer affect your movement. Hope this helps!

4 Likes