Hi!
I'm trying to rotate a 3D modele (MeshInstance) so that it faces the mouse position.
I'm stuck on this problem. First here is my project architecture:
First I have a 2D main scene like this:

The player3D scene is as follow:

Like you see I render a 3D player on a 2D scene via this script attached on the root node of the 2D scene -> Node2D:
extends Node2D
var viewport = null
var viewport_sprite = null
func _ready():
viewport = get_node("Viewport")
viewport_sprite = get_node("on_the_ground/player/Sprite")
viewport_sprite.texture = viewport.get_texture()
The camera is fixed and facing the player model like this:

So the first problem here is the approach itself.
My first unsuccessful attempt was to try to handle this in the 3D scene like this:
extends KinematicBody
func _physics_process(delta):
if Input.is_mouse_button_pressed(BUTTON_RIGHT):
var camera = $Camera
var from = camera.project_ray_origin(get_viewport().get_mouse_position())
var to = from + camera.project_ray_normal(get_viewport().get_mouse_position()) * 1000
get_node("MeshInstance").look_at(to, Vector3(0, 1, 0))
This script is attached to the root node of the 3D scene so "player3D"
I tried to use a rayCasting to convert the mouse 2D coordinates in a vector3 (to here)
Then I called look_at on the MeshInstance node to rotate it.
But the rotation is weird and rotate not only on the Y axis but other axis too.
My second attempt was to handle the rotation in the 2D scene, get the right angle and then rotate the 3D mesh accordingly.
The following script is attached to the root node of the 2D scene (the main scene)
func _process(delta):
if Input.is_mouse_button_pressed(BUTTON_RIGHT):
var rot = get_angle_to(get_viewport().get_mouse_position())
get_node("Viewport/player3D/MeshInstance").rotation.y = rad2deg(rot)
Here the rotation happens only on the Y axis, but the rotation seems to be out of sync with the mouse position. It rotates too fast.
Can you help me ?