- Home /
Checking if statement in higher frequency
I am making a cameraController Script and i wrote this code to rotate the camera around the player in accordance to the mouse input (movement in x and y axis):
public float maxAngle = 80f;
public float minAngle = 10f;
void MoveCamera()
{
//move around body and around y axis
transform.RotateAround(playerBody.position, new Vector3(0, 1, 0), Input.GetAxis("Mouse X") * moveSpeed * Time.deltaTime);
//move around body and around normal to (y, front of camera)
float yInput = Input.GetAxis("Mouse Y");
//if in range move
if ((transform.localRotation.eulerAngles.x <= maxAngle || yInput < 0) && (transform.localRotation.eulerAngles.x >= minAngle || yInput > 0))
{
transform.RotateAround(playerBody.position, Vector3.Cross(new Vector3(0, 1, 0), transform.forward).normalized, yInput * moveSpeed * Time.deltaTime);
}
}
and I call the func in Update. In the code im trying to avoid going above 80D angle and less the 10D. so im checking for situation when im hight or lower and if i am not in range i dont let the rotation go further in this diraction. The code is working but the problem is when i move my mouse fast the rotation goes beyond the wanted angles (the if statement not chacking fast enough). is there a way to check the if statement in higher frequency? so it wont miss the range.
Your answer
![](https://koobas.hobune.stream/wayback/20220612213339im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Input.GetMouseButtonDown(0) running through my if statments too quickly 1 Answer
Cross platform camera controlls 0 Answers
Rotate a crank with the mouse 0 Answers
Character Not Rotating 0 Answers
Rotate around, but track the mouse 1 Answer