3rd person template help!

Godot Version

4.6.1

Question

M trying to rotate the Characterbody3d when i press WASD but it rotates with camera y axis rotation ?

Script :

extends Node3D

var camera_rotation : Vector2 = Vector2.ZERO
var mouse_sens : float = 0.001
var max_y : float = deg_to_rad(80)

@export var character : CharacterBody3D

func _ready() :
	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
	
func _input(event) :
	if Input.is_action_just_pressed("escape"):
		if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
			Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
		else :
			Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
	
	if event is InputEventMouseMotion :
		var mouse_event : Vector2 = event.screen_relative * mouse_sens
		camera_look(mouse_event) 
	

func camera_look (mouse_movement : Vector2) -> void :
	camera_rotation += mouse_movement
	
	transform.basis = Basis()
	character.transform.basis = Basis()
	
	character.rotate_object_local(Vector3(0,1,0) , -camera_rotation.x)
	rotate_object_local(Vector3(1,0,0) , -camera_rotation.y)
	
	camera_rotation.y = clamp(camera_rotation.y, -max_y , max_y)

All i know is its because of line 30 in the script ; character.rotate_object_local(Vector3(0,1,0) , -camera_rotation.x)

This doesn’t appear to rotate with WASD it rotates with mouse movement.

You can simplify this code by removing the camera_rotation variable and resetting the basis, instead acting directly on the character and self’s rotation

func camera_look(mouse_movement: Vector2) -> void:
	character.rotation.y -= mouse_movement.x * mouse_sens
	rotation.x -= mouse_movement.y * mouse_sens
	rotation.x = clampf(rotation.x, -max_y, max_y)

Usually when you talk about TPS the movement is a combination of the direction set by the camera and the movement itself set by the cursor keys.

If you want something more like top down, then you can have:

1 Direction set by the camera and movement by keys

2 Direction and movement set by the 4 keys

3 Direction set by Left and Right to rotate the character and movement set for UP and DOWN to define Forward and Backward

All of this are possible options. So, what are you trying to accomplish?