I have an object using Quaternion.LookRotation() to look at target object, I would like to be able to restrict the rotation by being able to set the range that the object can rotate at, for example from 45 degrees to 180 degrees, this would mean the object does not rotate lower than 45 degrees and does not rotate higher than 180 degrees, currently my code looks like this:
void Start(){ baseRotation = transform.localEulerAngles; } Vector3 targetPos = Target.position; Vector3 dif = targetPos - obj.position; dif.z = 0; Quaternion lookAngle = Quaternion.LookRotation(dif, obj.up); print("angle: "+ Quaternion.Angle(lookAngle, Quaternion.Euler(baseRotation))); if (Quaternion.Angle(lookAngle, Quaternion.Euler(baseRotation)) < rangeMax - rangeMin) { targetR = lookAngle; } obj.rotation = Quaternion.Lerp(obj.rotation, targetR, Time.deltaTime * 100); } However this code makes sure that rotation both upwards and downwards equally does not exceed the same angle, which is not quite what I want, as I said I would like to set the start angle and the end angle. How would I do that? Could you post the code that would give me an idea?
Thanks in advance!