Hello. I found many issues with Mouse using for rotation, but a little bit of Stick with problem solved.
Here is an issue:
I want to limit X-axis rotation (vertical). With mouse controlls it is easy: mouse position equal to rotation. With Stick: current rotation + new rotation.
Here is a code:
public float hRotationSensitivity = 50f;
public float vRotationSensitivity = 30f;
public float minAngle = -45.0f;
public float maxAngle = 45.0f;
void Update()
{
// CAMERA LOOKING
float angH = Input.GetAxis("RightH") * hRotationSensitivity * Time.deltaTime * 5;
float angV = Input.GetAxis("RightV") * vRotationSensitivity * Time.deltaTime * 5;
// CL -- Rotate horizontal
Vector3 newRotationH = new Vector3(0, angH, 0);
transform.localEulerAngles = transform.localEulerAngles + newRotationH;
// CL -- Rotate vertical
Vector3 newRotationV = new Vector3(angV, 0, 0);
//Vector3 totalRotationV = transform.localEulerAngles + newRotationV;
//totalRotationV.x = Mathf.Clamp(totalRotationV.x, minAngle, maxAngle);
//transform.localEulerAngles = totalRotationV;
transform.localEulerAngles = transform.localEulerAngles + newRotationV;
}
Camera looking is work perfectly, but has no limits.
Code that is commented does not solve my problem. It makes some strange shaked movement.
Please, what I missed.
I want camera like in GTA V.

AdhikS
2
try this
if(camera angleY is < 45 && camera angleY is > -45 )
{
Vector3 newRotationV = new Vector3(angV, 0, 0);
}
Thanks for answers, but I make my own solution. =)
Here it is:
Vector3 newRotationV = new Vector3(angV, 0, 0);
transform.localEulerAngles = transform.localEulerAngles + newRotationV;
float x = transform.localEulerAngles.x;
if (x > 45 && x < 315)
{
if (x > 45 && x < 50)
{
transform.localEulerAngles = new Vector3(45, transform.localEulerAngles.y, 0);
}
else if (x > 310 && x < 315)
{
transform.localEulerAngles = new Vector3(315, transform.localEulerAngles.y, 0);
}
}
It possible to change digits to named variables.
However, its absolutely 100% work =)