rotate Y axis to face mouse

hi, i’m trying having a hard time making a script that will let my character always face the mouse, via the Y axis (top down style) but i am not having any luck. the hard part is that the camera is in a slight tilt so that it’s not 100% “top down” (about a 40° tilt) so is there anyway to take the position of the mouse relative to the center of the screen (since the character is always center anyways) and translate that to rotation for the character?

You can go with your approach of getting the vector of your camera to the screen center and then setting your object’s facing direction to the same vector. You might need to flip it to the correct orientation and you will have to come up with a solution what to do when the mouse is close to the center, because then it just becomes jittery.

public class RotateByMouse : MonoBehaviour {

    public Transform gameObjectToRotate;

    Vector3 middleOfScreen;

    void Start() {

        middleOfScreen = new Vector3(Screen.width/2, Screen.height/2, 0f);
    }

    void Update() {

        Vector3 camVec = Input.mousePosition - middleOfScreen;
        Vector3 flipped = new Vector3(camVec.x, 0f, camVec.y);
        gameObjectToRotate.LookAt(flipped);
    }
}