Endlessly map

Asked

Viewed 291 times

1

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

Next: Imagine the scene of the game Conceito do game

Where, the black square in which the "Player" is, is the camera view the rest are instantiated balls in random places on the map...

  • The game is a physics game, with the mechanics of Angry Birds, of throwing an object *

as the player in question, is always advancing to the right >>>, how can I make so that new balls are always generated and erased the previous balls <<< and the camera will always follow the player? follows a gif of behavior which I wish to:

http://i.imgur.com/0Ku8g2P.gifv

I just need a different point of view of how to assemble this mechanical problem with same logic! haha

Thank you from now on! On hold

  • I think the question is broad, because you did not specify the "rules" to generate the scenario. What I can say is that you can make a coordinate map (x, y, object), and tell where things are (for example, in the x 3400, y 200 will have a cloud). Thus, you edit the map regardless of the screen size. When drawing, just take what is on the coordinates of the screen (actually a little bigger, to draw things that are off the screen, but with some piece already appearing). Random gets tricky, unless you’re doing a "Flappy Bird," things where the scenery is disposable.

  • So, but in case I’m trying to create something infinite, I can’t specify a length length, height all right, but on the x-axis, whatever the map might be infinite, I will be disabling the red balls that are with a position smaller than that of the player + half of the screen, that way the player does not realize that they are being disabled, but I want infinitely the balls are generated in front of the player (in the case of those already generated)

  • You can do it. Simply delete the objects that are outside the screen (x < size of the largest ball) from the list and create new ones dynamically. If you prefer, don’t move the player, move all the balls (but I think that’s more boring to manage). What you can do, is after a certain X, make a "loop" in the pro player phase go back to zero after a certain X. Actually, it’s quite simple, the complicated is to explain :)

  • but from what point can I start generating? because for example, if I generated balls from x = 0 to x = 10, I want to start generating new balls in x = 11 to x = 20

  • HMMMMMM, I loved the idea of zeroing the x of the player, but the problem is that the player would notice, I want something very fluid, which generates the balls out of the field of vision of the player

  • Go generating as the player walks. Just generate outside the screen. You can initially generate 200 balls, and as you erase the ones that have passed, generates a new one in place.

  • When I speak of zeroing the X, there would appear no jump. The balls would be generated at the beginning as well. For example, if the maximum X is 20000, for example, the following balls would already be generated from scratch again. Your drawing routine, when X passes this, already picks up from scratch. It turns into a large horizontal loop. Only the map doesn’t repeat, because the dots change places.

  • I get it, I think as long as a ball is erased, it’s generated at a certain point in front of the player is a good idea, as far as zeroing out the X would complicate me into making a traversed distance system, so I’ll try to recreate the balls as soon as they’re erased! thanks for the opinion :D

  • This zeroing the X I spoke for you say it wants infinite. If the maximum distance fits in the variables that will use, not need. Just keep increasing the X over and over again, it’s easier. The problem is if the guy is too good, and the X number doesn’t fit in the type of variable you used. You have to foresee that in the code.

  • Okay, I’m going to try to implement both options so haha, I had a different idea in mind, it was good to see someone else’s vision! Thank you very much, helped me a lot the/

Show 5 more comments

1 answer

0

Man, it wouldn’t 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 the mechanics, and the fluidity of the game will never 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 pass by the player and give the impression of progression, and this way you can still stipulate an xMin that would be the value in which it disappears from the camera and when it reaches this value you destroy it and create another new one further on. It would look something like this, more or less, because I’m doing it with my head :

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
    }    
}

I’m sorry about some mistake in the code, but it was just to try to expose the idea, I hope it helps ! :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.