How to scroll background and how unity environment work

Iam working on scrolling background, the game is 2.5D infinite runner game and all my base platform is cube i have used this approach

a) Making camera and background fixed and moving base platform as soon as mesh get out of scene from left i am resetting its position on right but here iam facing lag in low end device but works fine on high end devices

So right now i am thinking of keeping base platform fixed and move camera, so camera will move continuously and as soon as platform will get out of scene it will reset it position to get into scene.

Is there is any limit of unity environment since i am thinking of moving my camera in x axis 2 units per frame which will move upto infinite is there is any issue in moving camera infinitely or after certain time unity will give me some error. So in this context i want to know how unity environment exactly work and is there is any limit in x,y,z axis.

There is a limit to how far you can go. At distances further from the origin physics gets less accurate. Can’t tell you exactly what distance will effect your game.

Unity uses floating point numbers for storing precision. One of the disadvantages with floats is they loose precision as you get very high or very low.

The limits that you are wondering about are discussed quite nicely in this article: Unity - Coordinates, Scales and creating huge games

So the major problem is of floating point errors which you can overcome by shifting your camera along with your world back to origin after it reaches certain limit.

Also there is a lot of discussion about this issue at UA and also all over Internet. You just need to search for it. :slight_smile:

For infinite runner,moving camera is not a best option if u are moving linearly. It will cause floating point precision errors.Better to keep the camera and player at a stationary point and move the obstacles around the player(like flappy bird concept).Inorder to give a feeling that player is moving,you can offset the background and platform texture with different speed like

BG texture offset speed=1/2 * Platform texture offset speed.

Apply individual textures to platform and BG,and use something like this to offset he texture UV

using UnityEngine;
using System.Collections;

public class TextureScroll : MonoBehaviour 
{
    //The speed at which texture scrolls
    public float scrollSpeed = 0.5F;
    
    void Update() 
    {
        
       //Update the offset value based on time
       float offset = Time.time * scrollSpeed;        
       //Apply the offset value back to the material(This will offset in X axis
       renderer.material.SetTextureOffset("_MainTex", new Vector2(offset, 0));   
    }
}