- Home /
Question by
ColorClad · Dec 03, 2016 at 07:44 AM ·
playermouse positionmouse look
How Can I Get the player to Look at the Mouse in a 3D game with the Camera at an Angle?
Here's my current code
public class LookControll : MonoBehaviour {
void Update () {
Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10);
Vector3 lookPos = Camera.main.ScreenToWorldPoint(mousePos);
lookPos = lookPos - transform.position;
float angle = Mathf.Atan2(lookPos.y, lookPos.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.down);
}
}
But my player never looks directly at the mouse and at some mouse positions it will make the character rotate more than it will in other places. I've been stuck on this for a while and can't find anything.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612101835im_/https://answers.unity.com/themes/thub/images/avi.jpg)