Godot Version
4.3
Question
I have a 3d game with a cat at 0,0,0 that needs to point towards the mouse. How can I do this in a simple way? I only need to rotate the cat’s y value. Any help would be appreciated.
4.3
I have a 3d game with a cat at 0,0,0 that needs to point towards the mouse. How can I do this in a simple way? I only need to rotate the cat’s y value. Any help would be appreciated.
I will just assume your SceneTree to have a canvaslayer or camera3d where your mouse is interacting from.
The cat is most likely a rigidBody3d or characterBody3d. 3d nodes typically possess a look_at(position)
method.
So all you need to do is check what get_viewport().get_mouse_position()
returns, then find out which z value your camera has. You can then have a Vector3 parameter which can be used for the look_at()
method for the cat.
At least that’s what I think.
The problem is the viewport has different coordinates than the actual map.
Then you need to make use of Raycasting which requires a Camera3d node.
I still don’t know your SceneTree setup or the specifics of the cat, maybe you can make sense of this topic here: How to make the 3d character to look at the mouse?
I already looked at this topic and it is outdated.