I am just lost trying to limit my characters rotation on the x axis… It sounds so simple yet it’s just the most complex thing! Maybe I’m just altering the wrong values.
So I’m having my Caspule Collider-based character swim in a 3D space, he can rotate along the Vector3.up axis to turn around in the x,z plane. I also have the character turn on his local Vector3.right axis (basically, altering his x-rotation, right?) so that he will swim in whichever direction the capsule is pointing up (so add force in the characters Vector.up axis). This all works well and makes for some nice 3D swimming control, however I’m having the hardest time trying to limit the angles at which my character can rotate along his Vecctor3.right axis. I’ve tried so many combinations from limiting the localEulerAngles.x, limiting the localRotation.x and even using an angle that the characters Vector3.up vector makes with the global Vector3.up axis. It seems like something that should be done very simply but it just either has the character rotating JUST past the point where I want him to rotate (and that’s not due to rotating after the limit has been reached) or the character will just continually rotate along the axis until I let go (basically ignoring the limit I set).
How can I make it so that when I use the RotateAround() method that the character will not rotate past a certain limit? I want him to rotate to the point that he will not be back-flipping underwater (so between local X angles 0 and 180).
Edit: Using Mathf.Clamp usually causes the character to start at the other end of the limit when reaching one end (so if it’s going 178, 179, 180 it will then go to 0, 1, 2) which I don’t want.