you did not put anything on the plane, the spawner has the script.
you did not even change the dimensions. (as said before it does exactly what you asked it to do)
Here this one will work, tested it.
(if you where thinking about taking this code, its not the latest version, this one is adapted for lostscience)
#
# RANDOM ASSETES PLACER - BY COTAKS
# (for endless runner)
from bge import logic, render
from random import uniform
from mathutils import Vector
def generator(cont):
#show mouse cursor (debugging)
render.showMouse(True)
own = cont.owner
scene = own.scene
spawner = scene.objects['Empty']
#how much to spawn at once
#WITH TRUE pulse, set amount at 1 or 2, it will spawn objects till spawn_max is reached
#WITHOUT TRUE pulse, it will (try to)spawn every object equal to the spawn_amount
#best setting = True pulse, spawn_amount = 1
spawn_amount = 200 # lower is slower but more accurate, higher causes objects to spawn in each other.
spawn_max = 3000 # +- max amount to spawn
if spawner['objects_spawned']+ spawn_amount <= spawn_max:
#the bigger the distance, the less objects of it will be spawn.
#objects to be spawn and their distance check
#place a property on the empty for every object you add (same name) to the dict below (for debugging)
objects = {
'tree': 7.50,
'stone': 7.50,
'flower': 0.50,
'flower2': 0.50,
'tree_trunk': 10.50,
'grass': 3.50
}
for obj in objects:
name = obj
distance = objects[obj]
random_placement(cont,name,distance,spawn_amount,spawn_max)
def random_placement(cont,name,distance,spawn_amount,spawn_max):
own = cont.owner
scene = own.scene
#DIMENSIONS of the landscape (N key in 3dview, scroll the quick menu to the top)
#for optimal results make sure that you have the origin(orange dot) of the terrain object on the lowest point(bottom) and centered on x/y axis.
landscape_z = 160 # defines the (max)spawn height (if it bugs out in single pulse mode then be sure this is at the right dimension or higher)
landscape_x = 1000 # defines the spawn area size (no use to set this bigger then the terrain)
landscape_y = 1000 # defines the spawn area size (no use to set this bigger then the terrain)
# z dimension of the tallest object that you spawn (in this case the tree)
spawn_height_offset = 11
#define objects
terrain_object = own
spawner = scene.objects['Empty']
#
# DONT CHANGE ANYTHING BELOW THIS LINE
#
z = terrain_object.worldPosition.z + (landscape_z + spawn_height_offset)
terrain_x = terrain_object.worldPosition.x + landscape_x / 2
terrain_y = terrain_object.worldPosition.y + landscape_y / 2
terrain_minx = terrain_object.worldPosition.x - landscape_x / 2
terrain_miny = terrain_object.worldPosition.y - landscape_y / 2
for i in range(spawn_amount):
spawner.worldPosition = [uniform(terrain_x, terrain_minx), uniform(terrain_y, terrain_miny), z]
z_vector = spawner.worldPosition + spawner.worldOrientation.col[2]
ray = spawner.rayCast(spawner, z_vector, (landscape_z + spawn_height_offset)*2)
if ray[0] == terrain_object:
#debug (can be removed)
render.drawLine(spawner.worldPosition, ray[1], [1,0,0])
check_range = distance
check_count = 0
direction_vectors = {
'vec_north' : ray[1] + Vector([0,check_range,0]),
'vec_north_east' : ray[1] + Vector([check_range,check_range,0]),
'vec_east' : ray[1] + Vector([check_range,0,0]),
'vec_south_east' : ray[1] + Vector([check_range,-check_range,0]),
'vec_south' : ray[1] + Vector([0,-check_range,0]),
'vec_south_west' : ray[1] + Vector([-check_range,-check_range,0]),
'vec_west' : ray[1] + Vector([-check_range,0,0]),
'vec_north_west' : ray[1] + Vector([-check_range,check_range,0])
}
for direction in direction_vectors:
#debug (can be removed)
render.drawLine(direction_vectors[direction], ray[1], [0,1,0])
check = spawner.rayCast(direction_vectors[direction], ray[1], check_range)
if not check[0]:
check_count +=1
if check_count == len(direction_vectors):
object_to_add = name
new_obj = scene.addObject(object_to_add, spawner, 0)
new_obj.worldPosition = ray[1]
face_direction(new_obj, [uniform(terrain_x, terrain_minx), uniform(terrain_y, terrain_miny), ray[1][2]])
spawner['objects_spawned'] += 1
#debug option (remove this, and object properties on the empty are not needed anymore)
#spawner[name] += 1
else:
spawner['spawns_skipped'] += 1
def face_direction(obj, vector):
track_axis = 1 # x,y,z = 0,1,2
turn_speed = 1.0 # 0.0 - 1.0
# face direction
obj.alignAxisToVect(vector, track_axis, turn_speed)
# head up
obj.alignAxisToVect([0.0,0.0,1.0], 2, 1.0)
put this script on the GROUND plane where you want to spawn assets.
always(single pulse)-python
it will spawn 200 assets instantly on the plane, if new one spawns it will instantly spawn 200 on that plane as well up to a max of 3000, you can change it in the script. This is not a neat way because you freeze the engine on a frame till everything is spawned. but none the less it works.