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))