- Home /
Randomly Generated 2D Level
So what I want to do is make a Procedural Random 2D game, with different levels every time the player dies.
I already have the game mechanics, and I could make my own level if I wanted to, but how would I go about making the level change after every respawn.
Here's a few images to show an example with 2-3 blocks of what the random script would do everytime I die, so you have a better idea of what I'm trying to achieve.
So what I want is the level to add/subtract blocks. Make them bigger or smaller(x scale only)
and also change their position with some limits.
They can only be so much units away from another block, or it will mess up (X and Y both or horizontally and verticcally)
So I know I need to probably do a lot of scripting with distance, and random numbers, but to be frank, I don't know where to start.
Also if you have any questions, please ask.
Thank you :)
Answer by Manco Capac · Jul 15, 2014 at 05:38 PM
For randomness use Random.Range()
To make random spaces, well i used something similar by instantiating objects relative to the previous objects. for example:
var lastObjPos : Vector3;
var obst : Transform;
Instantiate(obst,lastObjPos,Quaternion.identity);
lastObstPos = ((lastObstPos.x + Random.Range()),(lastObstPos.y + Random.Range());
This seems to be perfect for what I'm going for so far. I'll mark it as correct if everything goes right.
Your answer
Follow this Question
Related Questions
How can i make an infinite level? 4 Answers
How to save a scene that you randomly generated as a new level in your build settings? 1 Answer
How can I end a level and go to the next level 1 Answer
Has anyone made a successful Pixel Perfect Camera script for platformer games? 2 Answers
How do I know when an object is going under a Platform Effector 2D object? 0 Answers