Character rotating towards mouse based on fixed camera angle

Godot 4.5

Howdy all, I’m dipping my toes into 3D by working on a demo based on suggestion from a friend: making a Project Zomboid clone but fantasy. As such, I’m trying to replicate the way game’s control scheme and I can’t seem to find a way to get the head to point in the direction of the mouse correctly in respect to the fixed camera. I have tried various solutions and tutorials but no dice. I’m sure it’s just a case of Newbie Syndrome but any help provided would be greatly appreciated

Getting a 3D position in the game world from the mouse’s 2D position on the screen is a little trickier than in 2D.

I think the easiest way to do what you want is to use the input_event signal of the ground collision. When you click the ground or move the mouse over it, the signal will be sent and give you the position of the mouse “on the ground”.

Then you can rotate the character with something like this:

func _process(delta: float) -> void:
    var direction_vector: Vector3 = input_event_position - character.global_position
    character.rotation.y = lerp_angle(character.rotation.y, atan2(direction_vector.x, direction_vector.z), delta * turn_speed)

(Another way would be to get the mouse positions on screen and reverse project the character’s position on the screen, and calculate the rotation using those two 2D positions, but I’ve never done it that way so not sure how to do it exactly..)