Comments and answers for "Clamp Vertical Aiming"
http://answers.unity.com/questions/1443758/clamp-vertical-aiming.html
The latest comments and answers for the question "Clamp Vertical Aiming"Comment by unity_dA5TCa2krrACsQ on unity_dA5TCa2krrACsQ's comment
http://answers.unity.com/comments/1446185/view.html
You can't set a single axis rotation by using "transform.rotate.y =". Otherwise I would have done that already.Sun, 24 Dec 2017 03:45:34 GMTunity_dA5TCa2krrACsQComment by baboca on baboca's comment
http://answers.unity.com/comments/1443827/view.html
Then you need to clamp the rotation of the object with Mathf.Clamp(), not the force rotating it.
transform.rotation.y = Mathf.Clamp (transform.rotation.y, float minAngle, float maxAngle);
That is if you are rotating around y, otherwise just change it.
If that dosent work try using Quaternions instead of floats, and transform.rotation without specifying the direction of the rotation, that way you can do:
transform.rotation = Mathf.Clamp(transform.rotation, Quaternion min, Quaternion max);
You can use Vector3 to specify the angle instead of quaternions, but then you have to convert it using [Quaternion.Euler][1]
[1]: https://docs.unity3d.com/ScriptReference/Quaternion.Euler.htmlSun, 17 Dec 2017 22:38:20 GMTbabocaComment by unity_dA5TCa2krrACsQ on unity_dA5TCa2krrACsQ's answer
http://answers.unity.com/comments/1443790/view.html
The variable rotVertical is the amount the camera should change every frame. For example, if I'm not moving my mouse, it's 0. Clamping that would just set a min and max turning speed. So how would I clamp the final rotation?Sun, 17 Dec 2017 20:27:37 GMTunity_dA5TCa2krrACsQAnswer by baboca
http://answers.unity.com/answers/1443777/view.html
You have to clamp the value of rotVertical between the angles that you want your player to rotate to.
This will set the minimal and the maximal value that it can reach.
void Update () {
//Camera
float rotHorizontal = Input.GetAxisRaw ("Mouse X") * mouseSensitivity;
transform.Rotate (0, rotHorizontal, 0, Space.World);
rotVertical = Input.GetAxisRaw ("Mouse Y") * mouseSensitivity;
rotVertical = Mathf.Clamp(rotVertical, minimalRotation, maximalRotation);
cameraTransform.localRotation *= Quaternion.Euler (-rotVertical, 0, 0);
}Sun, 17 Dec 2017 19:43:37 GMTbaboca