Manual RotateAround
Hello guys,
I'm testing strange things on mobile and I have a problem with virtual joystick and camera rotation. I want to rotate my camera around the player following the joystick movement. How? If I turn the joystick on the right I want the camera rotates 90degrees, like if I'm turning my head on the right watching what there are.
Now, the problem is that RotateAround work in a slighly different way because it keeps rotating according to the angle passed in function. I fixed this putting a check between current rotation and input from joystick, blocking the function when I'm near to the rotation I want.
But the current problem is that if I pass 180degrees (e.g: from 179degrees to -179degrees), the function change rotation direction to reach the new angle (e.g: from 179degrees to -179degrees it rotates for 358 degrees instead of 2). And I don't want this, I want to reach the new angle (rotation) throght the shortest path.
I could probably calculate the difference between angles, and use negative or positive angle according to this difference. But I'm wondering if exist a simpler or more efficient way to do all this. Here is my shitty code, if helps:
private void LateUpdate()
{
float inputY = vjRightController.InputDirection.y;
if (inputY < 0)
{
inputY += 360f;
}
if (transform.localEulerAngles.y - inputY > 3f || transform.localEulerAngles.y - inputY < -3f)
transform.RotateAround(playerTarget.position, Vector3.up, vjRightController.InputDirection.y * Time.deltaTime);
}
InputDirection = new Vector3(0f, Mathf.Atan2(x, y) * Mathf.Rad2Deg, 0f);
Thanks in advance and sorry for my english