How to limit the rotation of my third person camera?
So, I'm making a script that controls my third person camera over-the-shoulder style. It kinda works similar to what I want, but it have a minor inconvenient: when I rotate too fast or for a long period in the Y axis, the camera loses the player from the view, unless I stop moving the player, which is when the camera returns to its place.
This is my code so far:
[SerializeField]
private Transform target;
private void LateUpdate()
{
transform.position = target.position;
transform.rotation = Quaternion.RotateTowards(transform.rotation, target.rotation, Time.deltaTime * 120f);
}
How do I limit the rotation of my camera? I found a lot of solutions here and the forum, but most of them are mouse look oriented, and the other solutions didn't work.
Answer by GingerBreadGames · Oct 06, 2020 at 12:47 AM
Hello! I'm pretty new to Unity but I hope this helps! So basically you need to create a public float called clampAngle and set it to whatever you want. Then add transform.rotation.x = Mathf.Clamp (transfrom.rotation.x, -clampAngle, clampAngle); I have it on the x axis, but it should work on any of them. Also, if this doesn't work still then I think I know why, and I can still help. Hopefully it does though!
Sorry that it is not organized properly, I don't really know how to do that
Actually I think I just misunderstood your question sorry
What do you thought it was about? And don't worry, you already state that you are new to Unity. Welcome, by the way.
I thought you were saying that you wanted to limit how far the camera can rotate. For example, you wouldn't be able to rotate it further than 90 degrees on that given axis