- Home /
Making object Clamp to Look Rotation of Camera
Below are my Code to make the Object facing the Camera but I wanna Clamp the Object rotation min and max rotation to -45 degree and 45 degree
function Update () {
var fwd = Camera.main.transform.forward;
fwd.y = 0.0;
transform.rotation = Quaternion.LookRotation(fwd);
}
Answer by Selaphiel · Apr 14, 2017 at 10:10 AM
Here, check this for rotation clamp, http://answers.unity3d.com/questions/659932/how-do-i-clamp-my-rotation.html
Also you can use transform.lookAt with lookrotation to look at object, i use this piece of code
public static void LookAtObject(Transform obj, float m_PopDistance)
{
transform.rotation = Quaternion.LookRotation (obj.forward);
transform.position = obj.position + obj.forward * m_PopDistance;
transform.LookAt(2 * transform.position - obj.position);
}
Your answer
Follow this Question
Related Questions
Camera following player gameObject,Camera follows player, with script attached. 1 Answer
Camera follow player when player rotates in y-axis 1 Answer
How to Rotate FPS Camera independent of Parent Player Object while WallRunning ? 0 Answers
Camera behaviour when looking directly up or down 0 Answers
How to look player and enemy at the same time using cinemachine FreeLook camera. 0 Answers