- Home /
How to Lerp and Clamp
So far I got my Camera to point to where the mouse is, but it really likes to spin out and I don't know how slow/Lerp it or clamp it so it doesn't turn when the mouse is in the middle of the screen.
And thats what I got so far
void Update()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100))
Debug.DrawLine(ray.origin, hit.point);
transform.LookAt(hit.point);
}
I had a problem similar to this one time. I was instantiating an object at the hit point. The ray would then hit the object and a new object would be created where the new hit point was detected closer to the camera. Eventually the object was so close, the camera was inside of it and the ray was able to hit the ground again. Something like this might be happening to you, causing the camera to look at a different position for a few frames, appearing to freak out. You could put some Debug.Log()'s for the location of the hit.point and see how drastically it is changing.
Answer by beck · Mar 12, 2014 at 05:58 AM
Instead of using transform.LookAt (which doesn't specify orientation), assign the rotation directly:
transform.rotation = Quaternion.LookRotation( (hit.point - transform.position).normalized );
Your answer
Follow this Question
Related Questions
third person camera 2 Answers
Camera gets stuck when cursor is locked 0 Answers
Rotation of the fps camera doesn't work in game when animated 0 Answers
camera zoom 1 Answer
How to prevent camera from clipping through walls with raycasts? 0 Answers