- Home /
Project abandoned.
Instantiate prefabs next to each other?
Hello. I have to achieve an endless driving game. I need to learn how I can instantiate ground prefabs and have them randomly generate right next to each other when the player is close to the edge of the current ground prefab so the gameplay is endless.
Input is much appreciated. Thank you.
Unfortunately that way wouldnt be endless because the world is limited in size so you would have to factor that in and transport the player back to the preceding edge of the world space.
What kind of driving game is it? That will dictate the best way to achieve it. Things like being able to do U-turns or reverse in the level etc. will also dictate the best way to achieve this.
Can you give us a little more information please?
Hello SacredGeometry. Thank you for taking the time out to reply. I do realize that the world would be limited in size and that the player would have to be sent back. But, considering the nature of the game, none of that would be a problem. I also agree that I might have worded the question wrong and it isn't necessarily a procedurally generated world that I'm looking for but rather a series of randomly instantiated prefabs to create a game level that won't repeat itself. The best game as a reference that I could find is PAKO Forever. You can see how the player gets sent back to the start as soon as they crash. That's essentially how I want it to be. Could you please drop in your two cents on how I can potentially instantiate prefabs at random next to eachother?
As I pointed out you need to outline the nature of the game or be more specific about your problem.
Providing each piece is the same size and I would advise you make it standardised to save yourself problems. Instantiating prefabs next to each other is literally just a matter of multiplying the size of the prefap in the axis you want by an incrementing number.
Will that be the best solution for all games No.
So be specific. You may want to keep the player still and have a buffered rolling floor ins$$anonymous$$d.
We cant advise you unless you explain what your game is and how you intend it to work.
Hello.
You are not asking about a function or something specyfic. You need to learn the structure, the basic the methods first... You need to go learn with some of the 10000 youtube tutorials about precedural developing. IF dont get one function or method to work, then come here to ask for that specyfic thing.
Bye"
Hello Tormento. Thank you for replying. I do agree I need to learn a lot more about procedural generation and this is far from what a true procedurally generated world would be but I do need help with something amongst these lines about spawning prefabs next to eachother at random. Do you think I should use triggers to spawn in a nearby ground prefab for when the player is about to reach the end? Thank you.
Answer by twrabetz · Mar 30, 2020 at 02:26 AM
You'll want to look Object Pooling in order to efficiently recycle your ground tiles. If you try to instantiate objects constantly it will be inefficient.
A random generation scheme for your tiles could be done in a lot of different ways. Maybe make a list or dictionary of your tile types and pick a random element to choose which tile to place?
Insightful! Thank you! I'm looking into object pooling as we speak. $$anonymous$$uch appreciated.
Also as other people have mentioned, if you go too far out into the world, it becomes an issue. One good solution is to just move the ground, and always have the player stay still. Another is after the player has traveled a long distance you can teleport then back to the origin.
Follow this Question
Related Questions
Terrain: Use as scenario (individual) and prefab (unchanged, reusable) 0 Answers
My objects instantiate at a strange z coordinate 0 Answers
How to instantiate particle effect after destroying it 2 Answers
Instantiating multiple objects, Destroying and instantiating on trigger + delay 0 Answers
How to instantiate a projectile only from the weapon prefab of the firing player? 1 Answer