I know very similar questions have been asked and, knowing unity, the exact question I’m asking has been asked. I’ve looked on unity answers for 2 days looking for an answer but I haven’t found it,if there is already an answer out there just link it to me.
I am making a 3rd person game where the player controls a space ship. I currently control the rotation of the ship with the keyboard, but I want to control it with the mouse.
I have found a script on unity answers that makes the ship literally face the mouse, but I want the ship to face where the mouse is pointing. The current script I have means that if I put my mouse in the middle of the screen, the ship faces me, this is not what I want. If my mouse where in the middle of the screen I want the ship to face directly away from me, at the mouse as if the mouse is further away from the camera than the ship.
Here is what I have so far:
var lookFactor = 0.8;
function Update () {
var distance = (transform.position.z - Camera.main.transform.position.z)*lookFactor;
var position = Vector3(Input.mousePosition.x, Input.mousePosition.y, distance);
position = Camera.main.ScreenToWorldPoint(position);
transform.LookAt(position);
}
But like I said this makes the ship face the cursor, not where the mouse is pointing in the world. Any help appreciated.