Random side scroller level generation

Im trying to figure out a way of randomly generating a 2d level for a side scroller game. I have a flat level floor all ready to go but I’m currently working on platforms for the player to jump on to. I can get the platforms to spawn, but i would like it to be more random. Any help would be greatly appreciated.

var blockplatform:GameObject;
var blockplatform2:GameObject;
var blockplatform3:GameObject;
var lastplatform:GameObject; 
var lastplatform2:GameObject;
var lastplatform3:GameObject;
private var deltaDistance:float;
private var nextStop:Vector3;
private var nextStop2:Vector3;
private var nextStop3:Vector3;
function Start(){
	nextStop = transform.position + Vector3.forward * 0.1;
	nextStop2 = transform.position + Vector3.forward * 0.1;
	nextStop3 = transform.position + Vector3.forward * 0.1;
}
function Update () {
	var currPos:Vector3 =transform.position;
	var currPos2:Vector3 =transform.position;
	var currPos3:Vector3 =transform.position;
	//print(Vector3.Distance(nextStop3,currPos3));
	if(Vector3.Distance(nextStop,currPos)>20){
		CreateNewplatform();
		
		nextStop = transform.position + Vector3.forward * 0.1;
	}
	if(Vector3.Distance(nextStop2,currPos2)>80){

		CreateNewplatform2();
		
		nextStop2 = transform.position + Vector3.forward * 0.1;
	}
	if(Vector3.Distance(nextStop3,currPos3)>100){
		
		CreateNewplatform3();
		
		nextStop3 = transform.position + Vector3.forward * 0.1;
	}		
}
function CreateNewplatform(){
    	var insPos:Vector3 = lastplatform.transform.Find("end_end").transform.position;
   		var newplatform:GameObject = Instantiate(blockplatform,insPos, lastplatform.transform.rotation);
    	lastplatform = newplatform;
}
function CreateNewplatform2(){
    	var insPos:Vector3 = lastplatform2.transform.Find("end_end2").transform.position;
   		var newplatform2:GameObject = Instantiate(blockplatform2,insPos, lastplatform2.transform.rotation);
    	lastplatform2 = newplatform2;
}
function CreateNewplatform3(){
    	var insPos:Vector3 = lastplatform3.transform.Find("end_end3").transform.position;
   		var newplatform3:GameObject = Instantiate(blockplatform3,insPos, lastplatform3.transform.rotation);
    	lastplatform3 = newplatform3;
}

I think before you get to the code side of it you might need to do some design…

What are the rules for generating the platforms? Specifically are there certain constraints that need to be met in order for the “randomly” generated platforms to be playable?

Once you have worked out the rules it should be pretty trivial to code them.

Sorry, I should have been more clear. my bad. Anyway, in my game I have 3 platforms that I want generated. The first level is almost always there and generates every 10 - 20 m. Level 2 platforms, are high enough to jump on if the player is currently on a level one platform, but not if there on the level floor. So level 2 platforms need level1 platforms. Level 3 platforms require level one and level 2 platforms so the player can jump right up level 3 platforms are the ones generated less often than level2 platforms. However they need to be lined up so level 3 platforms are spawned but the player couldn’t reach them. The reason I want some what random platform generation is so the user has a slightly different experience every time they play the game.
platform------------------------------------lv3_
platform-------------------lv2_
platform–lv1_
game_floor________

Very simple random map generation, I could create you a small prototype within C sharp if you want. But you use javascript, so this may not be optimal for you.

I’m looking for a similar setup- I’ll take you up on that offer Dabeh, if it’s not too much to ask that is. :slight_smile: