Random block spawning

I am making a runner game (ex. Temple run) and I am trying to make a random map spawner. How can I do that? I really need to know :slight_smile:

i not sure if understand well, but you want that the terrain generate randomly around the player right?

if so the easiest way is make first off all all terrains compatible each other , for example a terrain can have mountains, but MUST end with a planes.
the planes should have the same color.
the terrain must be big the same size.

after that put a empty in each point where is the center of the potential terrain, and a sensor Near with property “player” (supposing that player is one) .
make the radius of the near sensor more or less 1.5x more big than necessary , (for example 1500/2000)
if positive : addObjectRandom
if negative: endObject add
these last piece probaly require some lin of code

This is actually pretty easy and can be done without even touching Python:
Add a spawner object wherever you want one (for organization, name it.)
Go into the logic editor and add a “random” sensor. As you would expect, that does pretty much all the random script for you.
add an “edit object” actuator. By default, this is set to “add object.” Create any object in another layer and be sure to name it so Blender can search for it for you.
Select that object in the “Object” bar (it may keep its original name.)
Go over to where it reads “Time.” Select any amount of time you want the object to stay in the scene (I believe it counts by logic tick, so if you want it to remain in the scene for a while, it’ll have to be a pretty high number.)
You can also select Pulse On (’’’) in the sensor, and select how long you want the breaks to be between spawns, but since you’re using a “random” sensor, it’s not needed. Place these anywhere you need them.
Play around with your settings a bit. You can also use the “collision” (since they removed “touch”) sensor combined with the “random” sensor. It all really depends on what you want it to do.

effectively not need python, the object added can ends with the same sensor setup of Near sensor of the spawner.
just probably with a range a bit more little

spawner(empty)
if near.positive -> randomAddObject()

map(mesh)
if near.negative -> endObject()

EDIT: the range must be the same, probably need one “flag” on the spawner (to avoid to spawn mutliple maps)
EDIT2: mhh… i guess need python :smiley:

No Python needed, Marco. Then again, I’m a fan of pushing the logic bricks beyond their intended use…

Much more simpler:

  • add an object to be spawned at an hidden layer

  • add an emitter object (empty) to your maze

  • create and assign an action to the emitter

  • the action should describe a position/orientation at each frame (whole number) where you want the object to spawn.

  • add a property “randomFrame” (int) to the emitter

  • add this randimization behavior:
    [LIST]

    • any sensor that detects a new object should be spawned
    • AND/OR controller
    • RandomActuator ( Distribution: Int Uniform; Property: randomFrame; Min:/Max: the start and end frame number of your action)
  • add this frame play behavior:

    • the sensor/controller from above:
    • ActionActuator (Mode: property, Property: randomProperty)
  • add this spawning behavior:

    • the sensor/controller from above:
    • EditObjectActuator (Mode: Add Object)

[/LIST]

The path:

The result:

Attachments

RandomSpawn.blend (83.5 KB)