- Home /
Game works on old iPhones, less than 6s plus. Player movement lags bad on 6s or greater.
My game isn't too complex. I'm pooling all my objects. Running on low quality. Anti aliasing and vsync are off. Not using metal graphics. Why does a game have performance issues on the new iPhones and not the old ones? Basically the player movement lags too bad to play the game without dying. I first created my game on Unity 2017.3.0 So, I build it on Unity 2017.1.0 and the game still had the lag on new iPhones. I then tried Unity 5.6.5, still same lag. Here Is my code for my player movement:
public class Cat : MonoBehaviour {
public float speed = 15f;
public float mapWidth = 3f;
private Rigidbody2D rb;
void Start() {
rb = GetComponent<Rigidbody2D>();
}
private void FixedUpdate(){
// Controls to move player in Unity
float x = Input.GetAxis("Horizontal") * Time.fixedDeltaTime * speed;
Vector2 newPosition = rb.position + Vector2.right * x;
newPosition.x = Mathf.Clamp(newPosition.x, -mapWidth, mapWidth);
rb.MovePosition(newPosition);
// Controls to move player on Phones
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Stationary){
Vector2 touchPosition = Input.GetTouch(0).position;
double halfScreen = Screen.width / 2.0;
//Check if it is left or right?
if (touchPosition.x < halfScreen){
rb.MovePosition(rb.position + Vector2.left * Time.fixedDeltaTime * speed);
//transform.Translate(Vector2.left * speed * Time.fixedDeltaTime); // Correct movement
if(transform.position.x <= -3f){
transform.position = new Vector2(-3f, transform.position.y);
}
}
else if (touchPosition.x > halfScreen){
rb.MovePosition(rb.position + Vector2.right * Time.fixedDeltaTime * speed);
//transform.Translate(Vector2.right * speed * Time.fixedDeltaTime);
if (transform.position.x >= 3f){
transform.position = new Vector2(3f, transform.position.y);
}
}
} //end if
}
void OnCollisionEnter2D(){
FindObjectOfType<GameManager>().EndGame();
}
}
Answer by Mobazy · Jul 06, 2019 at 12:47 PM
I solved this by just increasing the application frame rate.
public class Example { void Start() { // Make the game run as fast as possible Application.targetFrameRate = 300; } }