CharackterBody3D Player movement not working

Godot ver.4.3

I am following a youtube tutorial and i’m having some issues with the player movement. At first when you load the game everything seems normal but soon after the player doesnt move like it should. For example when I press W the player should move forward but it goes in the oppisite direction as if were pressing S and the same happens when I press A it goes right instead of left. The whole things just messed up but i’m not sure if this is happening because of the movement script or because of the camera. I Think it’s rather because of the camera, not sure, but it is not set up well so I dont know if it just looks as if the player is not moving right or if the camera just makes it look like that.

I’m not really sure but either way here is the error it shows:
player.gd:38 @ _ready(): Node not found: “camroot/h” (relative to “/root/Level 1/Player”).

And here is the part of the code Ithinks causing trouble. The highlighted part is the error:

@onready var camrot_h = get_node(“camroot/h”)

func _ready() → void:
pass

func _input(event: InputEvent) → void:
if event is InputEventMouseMotion:
aim_turn = -event.relative.x * 0.015
if event.is_action_pressed(“aim”):
direction = camrot_h.global_transform.basis.z
func _physics_process(delta: float) → void:
var on_floor = is_on_floor()
if !is_dying:
attack1()
if !on_floor:
vertial_velocity += Vector3.DOWNgravitiy2delta
else:
vertial_velocity = Vector3.DOWN
gravitiy/10
if Input.is_action_just_pressed(“jump”) and (!is_attacking) and on_floor:
vertial_velocity = Vector3.UPjump_force
angular_acceleration = 15
movement_speed = 0
acceleration = 1
if (attack1_node_name in playback.get_current_node()):
is_attacking = true
else:
is_attacking = false
var h_rot = global_transform.basis.get_euler().y
if (Input.is_action_pressed(“forward”) || Input.is_action_pressed(“backward”) || Input.is_action_pressed(“left”) || Input.is_action_pressed(“right”)):
direction = Vector3(Input.get_action_strength(“left”) - Input.get_action_strength(“right”),
0,
Input.get_action_strength(“forward”) - Input.get_action_strength(“backward”))
direction = direction.rotated(Vector3.UP, h_rot).normalized()
if Input.is_action_pressed(“sprint”) and (is_walking):
movement_speed = run_speed
is_running = true
else:
is_walking = true
movement_speed = walk_speed
else:
is_walking = false
is_running = false
if Input.is_action_pressed(“aim”):
player_mesh.rotation.y = lerp_angle(player_mesh.rotation.y, camrot_h.rotation.y, delta
angular_acceleration)
else:
player_mesh.rotation.y = lerp_angle(player_mesh.rotation.y, atan2(direction.x, direction.z) - rotation.y, delta*angular_acceleration)

Just so you are aware, Godot considers -z as forward, -x as left.

Your methods for forward.strength - backward.strength, should be reversed. same for left and right.

Or you can rotate your camera and player mesh 180 degrees to fit your movement methods.

Okey, I’ve tried it and I think I found the problem. So the player movement is actually right and the camera works too. When you first load the game you can go forward,right,left,sprint and attack but only in one direction idk if that makes sense. So basically if the game loads and I press D i move to the right, like I should, but the second time when I press D again the player moves forward instead of to the right again. It’s kinda like a 2D game where you can only go into one direction forward.