How can I make the camera not overreach a limit of rotation one axis.
They there, I am currently trying to make something like a Skate game.
And I am trying to make a camera that rotates with the player, but stays on the same offset behind him. That gives a pretty good effect, until this happens:
https://gyazo.com/0050e02244cd8018d1b9b0ce7192bcd1
As you can see, the camera rotates to a point to which the player isn't even visible any more.
I want the camera to stay like this:
As you can see, about 15 and -15 on the Y axis of the camera's rotation.
This is the closest I've come to it so far:
void Update () {
Vector3 targetCamPos = offset + target.position;
transform.position = Vector3.Lerp(transform.position, targetCamPos, smoothing);
if(transform.rotation.y > 15 || transform.rotation.y < -15)
FixTurning();
else
transform.rotation = Quaternion.LookRotation(target.forward);
Debug.Log(transform.eulerAngles.y);
}
void FixTurning()
{
float yAngle = transform.eulerAngles.y;
if (yAngle > 15 || yAngle < -15)
transform.Rotate(0, Mathf.Clamp(yAngle, -15, 15), 0);
}
And it doesn't work... at all.
Thanks, Lepto.
Your answer
Follow this Question
Related Questions
Some problems with handmade basic player controller 0 Answers
How to make character rotate in direction of movement? 1 Answer
[C#] Rotate player to camera forward look 0 Answers
Player not moving in the right direction instantly 1 Answer
How do I make my player's movement relative to Main Camera's direction? 1 Answer