- Home /
Camera Rotation Problem on Mobile
Hello everyone.
I make a 2d platformer game with Unity 2017.3, I have tested my game in my some android devices.
I have a problem when I try to rotate my camera on android. I have two cameras, Main camera is orthographic camera and another one is perspective camera. the perspective camera is a child of orthographic camera.
There is no problem when I run my game in unity editor, but after I build on android, it suddenly stop when the rotation is called. The game doesn't crash or anything, it's just not responsive anymore. it is like a lag but it take a long time.
this is my rotation script
public float time;
bool isRotating = false;
private float currentLerpTime;
private float perc;
Quaternion camTarget;
//Animator anim;
private void Start()
{
//anim = GetComponent<Animator>();
}
public void Rotate(bool right)
{
isRotating = true;
currentLerpTime = 0;
if (right == true)
{
//anim.SetBool("Right", true);
//anim.SetBool("Left", false);
camTarget = Quaternion.Euler(0, 0, 90);
//transform.rotation = Quaternion.Slerp(transform.rotation, camTarget, 1);
}
else {
//anim.SetBool("Right", false);
//anim.SetBool("Left", true);
camTarget = Quaternion.Euler(0, 0, 270);
//transform.rotation = Quaternion.Slerp(transform.rotation, camTarget, 1);
}
StopCoroutine("Rotater");
StartCoroutine("Rotater");
}
public void RotateBack()
{
isRotating = true;
currentLerpTime = 0;
camTarget = Quaternion.identity;
//transform.rotation = Quaternion.Slerp(transform.rotation, camTarget, 1);
//anim.SetBool("Right", false);
//anim.SetBool("Left", false);
StopCoroutine("Rotater");
StartCoroutine("Rotater");
}
//private void Update()
//{
// if (isRotating)
// {
// if (currentLerpTime > time)
// {
// currentLerpTime = time;
// }
// else
// {
// currentLerpTime += Time.deltaTime;
// }
// perc = currentLerpTime / time;
// transform.rotation = Quaternion.Slerp(transform.rotation, camTarget, perc);
// if (currentLerpTime >= time)
// {
// isRotating = false;
// }
// }
//}
IEnumerator Rotater()
{
while (true)
{
if (isRotating)
{
if (currentLerpTime > time)
{
currentLerpTime = time;
}
else
{
currentLerpTime += Time.deltaTime;
}
perc = currentLerpTime / time;
//Vector3 rot = transform.eulerAngles;
//rot.z = Mathf.Lerp(rot.z, camTarget.eulerAngles.z, perc);
//if (rot.z < 0)
// rot.z += 360;
//transform.eulerAngles = rot;
transform.rotation = Quaternion.Slerp(transform.rotation, camTarget, perc);
Debug.Log(transform.rotation.eulerAngles);
if (currentLerpTime >= time)
{
isRotating = false;
}
}
yield return null;
}
}
as you can see from script above. I have tried with the animation and update() as well. but result still same.
to make it more complicated, it is just happens in some area of the map. this is still prototype, so there is still not many things in the map.