Question by
Spacemarine658 · Dec 13, 2015 at 04:34 PM ·
rotationplayerlookat
Trouble with player lookat
So I'm making an fps from scratch and need to have the player rotate when the mouse moves but with just this
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition + Vector3.forward * 2f);
transform.LookAt (mousePos);
the player rotates too fast and theres no bounding box and i looked and can't find anything on this
Comment
Answer by Spacemarine658 · Dec 13, 2015 at 05:31 PM
Ok so I found some stuff and got that part to work but now it wont continue to rotate if the mouse is off screen any help?
void FixedUpdate()
{
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition + Vector3.forward * 2f);
Vector3 direction = mousePos - transform.position;
Quaternion toRotation = Quaternion.FromToRotation(transform.forward, direction);
transform.rotation = Quaternion.Lerp(transform.rotation, toRotation, 0.1f * Time.time);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612052449im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
TopDown Look at mouse 0 Answers
How to rotate object in sphere 0 Answers
Movement/Rotation Methods Don't Work Together 0 Answers
Creating a Window - Camera movement 0 Answers
Problems with rotating the player on the Y axis C# 0 Answers