If I understand correctly, you want to rotate the velocity vector as much as the camera rotates?
e.g.: Player is pushed left. Player rotates camera to the right 90 degrees. Player’s velocity is still pointing to the player’s left, even after rotation, when normally it would now be behind them.
If that’s the case, you can rotate the velocity at the same time as when you’re capturing mouse input to rotate the camera. For example, my FPS shooter camera script rotates the camera vertically around the x axis. The camera is the child of a Head node, which is rotated around the y axis.
This is my simple shooter FPS behavior I already use:
func _unhandled_input(event: InputEvent) -> void:
## Camera movement
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
var yaw = -event.relative.x * HSENSITIVITY
var pitch = -event.relative.y * VSENSITIVITY
head.rotate_y(yaw)
camera.rotate_x(pitch)
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-80), deg_to_rad(90)))
If you want to change the player’s velocity according to the camera’s rotation, you need to use quaternions. Before applying the camera rotation, save the initial rotation, then apply the rotation. Save the final rotation, and calculate the difference in rotation, then multiply your velocity by the difference in rotation.
I use linear_velocity because my player node is a RigidBody3D. Depending on your player, you might want to use velocity instead.
func _unhandled_input(event: InputEvent) -> void:
## Camera movement
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
var yaw :float = -event.relative.x * HSENSITIVITY
var pitch :float = -event.relative.y * VSENSITIVITY
var initial_rotation :Quaternion = camera.global_transform.basis.get_rotation_quaternion()
head.rotate_y(yaw)
camera.rotate_x(pitch)
camera.rotation.x = clamp(camera.rotation.x, deg_to_rad(-80), deg_to_rad(90))
var final_rotation :Quaternion = camera.global_transform.basis.get_rotation_quaternion()
# Difference in rotation
var delta_rotation :Quaternion = initial_rotation * final_rotation.inverse()
# Multiply your velocity by the difference in rotation
linear_velocity = linear_velocity * delta_rotation
If that doesn’t help, could you share your movement and camera script?