Hi guys thanks for looking.
I have a question that i have been thinking about all day.
I want to create a game that allows you to jump from platform to platform but have the platforms constantly be created in an upward and side ward direction. I have already created the pooling system so that we are not creating and destroying a lot of objects.
The thing i am finding hard to conceptualise is being able to dictate where they are created(Left, right, up, down) so that the player can go in any direction and there will always be a platform that he can get too.
The main thing that pops in my mind is. How do i know where to place it and before i place it make sure that there is not another block in the way.
The second thing is that if i am falling to the ground how will i be able to dictate, Create a block below you.
I am just finding it hard to design this so that i have complete control but it is also totally random.
Any ideas would be greatly appreciated.
1 Answer
1
Random Procedural generation where there is always a way to continue is very difficult.
However in a short amount of time I managed something similar. It looks very “uniform” but its pretty effective and you can improve it if you want. Here’s the code
// How high above the player each platform is
var genHeight = 3.0;
//Initialize varibles
var upr = false;
var upl = false;
var ri = false;
var le = false;
var uprCube;
var uplCube;
var riCube;
var leCube;
var thePlayer;
//Find the player if he wasnt set in te inspector
function Start() {
if (thePlayer == null) {
thePlayer = GameObject.Find("Player");
}
}
function Update () {
//Check if we nedd to generate a platform in the top right
if (upr == false) {
uprCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
uprCube.transform.position = thePlayer.transform.position + Vector3(1,genHeight,0);
upr = true;
}
if (uprCube != null) {
if (uprCube.transform.position.y <= thePlayer.transform.position.y) {
upr = false;
ri = false;
}
}
//Check if we nedd to generate a platform in the top left
if (upl == false) {
uplCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
uplCube.transform.position = thePlayer.transform.position + Vector3(-1,genHeight,0);
upl = true;
}
if (uplCube != null) {
if (uplCube.transform.position.y <= thePlayer.transform.position.y) {
upl = false;
le = false;
}
}
//Check if we nedd to generate a platform in the below the player to the right
if (ri == false) {
riCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
riCube.transform.position = thePlayer.transform.position + Vector3(1,-1,0);
ri = true;
}
if (riCube != null) {
if (riCube.transform.position.x <= thePlayer.transform.position.x) {
ri = false;
}
}
//Check if we nedd to generate a platform in the below the player to the left
if (le == false) {
leCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
leCube.transform.position = thePlayer.transform.position + Vector3(-1,-1,0);
le = true;
}
if (leCube != null) {
if (leCube.transform.position.x >= thePlayer.transform.position.x) {
le= false;
}
}
}
I probably over complicated things but it works pretty well (it needs some improvement.) If you want to see my sample project heres the dropbox 1. In the mean time. Happy coding!
I'm kinda confused. Are you trying to have it so when the player jumps off a platform a new one is created under him?
– swordofnoahBasicly when a player is in the game there is always platforms everywhere up, down, left, right so that the player always has somewhere to jump to. But do this in a way so that it is completely endless, if a player wants to they can just keep going left or keep going right or up.
– john-essyHere is a visual concept of what i am thinking https://dl.dropbox.com/u/6090006/Platform%20game.png
– john-essyOkay I'll try and figure this out. Thanks for the info.
– swordofnoahAdded an image to try and help you visualise what it is i am trying to do :D
– john-essy