I asked about how to randomize the levels in a basic Runner game on UnityAnswers and was told this:
I just want to double check if that is how most people do it. Because I know that people like yome (maker of Chop Chop Runner) have made similar games.
Is that how most game developers do it? Or do they do it a different way?
I would do it that way, and destroy the different sections as they went off the play field. Since they won’t ever be used again, no reason to keep the memory taken up.
You could check position relative to the player, or use triggers, or things of that sort. For instance, if you make the chunks larger then the screen, then you can destroy the last chunk when you enter a trigger on it, and load the next chunk at the same time. I think based on player position is probably the best one though.
As far as the player position, you would check the players transform and the different section’s transforms, if they are say 200 units behind the player, then it’s more then likely not possible to be seen by the player anymore, so destroy that sections prefab. It just saves checking for collisions and instead compares two x, y, or z values, whichever direction you have it going. I think the position one is technically faster as it’s just comparing is x <= player.x-200, as opposed to checking the minimum of 8 points and if the value of 8 other points are inside of that range.
I don’t think it matters on something like this because it’s probably not all that graphically intense (most runner style games aren’t anyway) so checking the maybe 10-15 seconds on a collision won’t really matter. I just try to optimize where I can.
Also, rather then having the trigger collision on each prefab, I’d simply have it surround and follow the player. If it collides, do nothing, if it doesn’t collide, destroy.
As far as complexity in programming, I don’t know which is easier for you personally. The transform position is probably easier to figure out then collision and what it hit and so on. It’s up to you. Whichever you feel more comfortable with.
EDIT: OH, you can also use the destroy check to run the instantiation of the next chunk, that way you only have to do one check.
Also, I was going under the assumption that all sections will be the same unit size, so you’d simply add the length of the sections onto the instantiate position. Like I said, I would instantiate the new section of the level right before I destroy the last section.
I would make a public variable on something like the camera that keeps position and size of the last made object, and set the transform of the new object to the that last objects transform + the size. Then in the start event of the prefabs, set the public variable to the new size and position. At least, that’s how I’d do it.