Generate map infinitely

1

I'm developing a game and I just found a rather boring difficulty, it's a logic problem ...

Next: Imagine the scene of the game

Where,theblacksquarewherethe"Player" is, is the view of the camera the remaining ones are balls instantiated in random places of the map ...

  • The game is about a physics game, with the mechanics of angry birds, to throw an object *

As the player in question, it is always moving to the right > > >, > > Is the camera always going to accompany the player? follows a behavior gif which I wish:

link

I just need a different point of view on how to build this mechanic, problem with logic itself! haha

Thanks in advance! I'm waiting

    
asked by anonymous 06.03.2016 / 21:55

1 answer

0

Dude, would not it be interesting for you not to move the camera and the player, but only the obstacles?

Because it makes it so much easier for you to handle mechanics, and the fluidity of the game is never going to be influenced. For example, each ball will have in its Update () method a line of code that will decrease the "transform.position.x", so they will always go through the player and give the impression of progression, and this way you can still stipulate an xMin that would be the value at which it disappears from the camera and when it reaches this value you destroy it and create a new one further ahead. It would be something like this, more or less, because I'm making a headache:

public float xNovo=15 //Estes valores sao hipoteticos, imagine que o seu player esta 
na posicao 0, e a camera consegue alcancar ate o 10, logo o 15 estaria 5 posicoes a frente.

public float xMin=-15 //Se a camera alcanca ate o 10 para a frente o mesmo vale para tras, 
logo o -15 seria 5 posicoes apos a bolinha ultrapassar a camera

public GameObject novaBolinha; //Aqui voce arrasta o prefab da bolinha

void Update(){
    transform.position= new Vector3(transform.position.x-2,transform.position.y,
    tranform.position.z); // nesta linha a bolinha vai andar constantemente para tras
    e o valor 2 seria a velocidade;

    if(transform.position.x<=xMin){

        float yNovo = Random.Range(10.0f,0.0f); //Esta linha gera um y  aleatorio para o novo 
        obstaculo, lembre que os valores podem variar no seu projeto

        Instantiate(novaBolinha,new Vector3(xNovo, yNovo, 0),transform.rotation); // ira criar 
        a nova bolinha la na frente        

        Destroy(this.gameObject); //Voce destroi o objeto por ultimo por questoes estruturais
        de ordem de execucao
    }    
}

Sorry for some error in the code, but it was just to try to expose the idea, hopefully help! :)

    
22.03.2016 / 21:45