My 3D moveset doesn't follow my mouse based camera

So I’m relatively new to Godot, mostly working with 2D platformers, but I’m fiddling around with 3D games and wanted to test the waters with a simple 1st person moveset. I’m using the default GDScript for 3D moveset, but I added mouse based camera movement using a Bramwell Tutorial on YT.

Tutorial: First Person Movement In Godot 4

I have the updated code for the camera movement but the moveset doesn’t follow the camera. So if I look forward and press Forward, I move forward. However if I look backwards and press Forward, I go backwards. I can’t really understand if they tutorial covered it, but I couldn’t find a solution for it regardless. If anyone has a solution for this and can keep it simple enough for a beginner to understand, it’d be very much appreciated!

Here’s my code for anyone to help out!

@onready var Neck := $Neck
@onready var Cam := $Neck/Camera3D

func _unhandled_input(event: InputEvent) → void:
if event is InputEventMouseButton:
Input.mouse_mode = (Input.MOUSE_MODE_CAPTURED)
elif event.is_action_pressed(“ui_cancel”):
Input.mouse_mode = (Input.MOUSE_MODE_VISIBLE)
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
if event is InputEventMouseMotion:
Neck.rotate_y(-event.relative.x * 0.01)
Cam.rotate_x(-event.relative.y * 0.01)
Cam.rotation.x = clamp(Cam.rotation.x, deg_to_rad(-30), deg_to_rad(60))

Hello @dascubz04! Maybe you forgot write direction based on Neck?

var direction = (Neck.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
1 Like

Yeah that solved it :smile: Thanks!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.