I’ve been searching for a routine or way to keep objects randomly placed in the game arena from overplaping. The closest I came to solving this problem was to use collision detection on every object created to the visible layer, this became very costly as I have several to a dosen objects on the screen at a given time. This was not as asetheticly pleasing as I would like, both objects are created, then one is destroyed, it would lead the player to believe that the game is “glitched,” but I tried searching python and other examples to create an effective way to keep objects from overlaping other objects. I would conclude that Python would be the problem solver here, has anyone had this problem? I would assume that thoes Blender gamers that have sucessfully created puzzle games or Asteriods clones would have this problem, and possible a solution. Maybe some one could provide a coded example or other way to solve this problem.
i have a script that i wrote a long time ago that adds objects randomly in a specified area. (i used it for a plane game to add spaceships in different spots evey time the game was played). well anyway, the objects never overlap because they are placed on a “grid” layout system.
here is the script…
import GameLogic rand=GameLogic.getRandomFloat() bland=GameLogic.getRandomFloat() gland=GameLogic.getRandomFloat() cont=GameLogic.getCurrentController() owner=cont.getOwner() xpos=-(owner.size/2) ypos=-(owner.size/2) if owner.obnumber>owner.counter: randpos=int(rand*((owner.size/owner.obsize)+1))*owner.obsize blandpos=int(bland*((owner.size/owner.obsize)+1))*owner.obsize glandpos=int(gland*(((owner.height2-owner.height1)/owner.obsize)+1))*owner.obsize owner.setPosition([xpos+randpos,ypos+blandpos,owner.height1+glandpos]) if owner.obnumber<owner.counter: owner.done=1
now, you have to set up some logic bricks,and some properties
here’s a pichttp://www.freewebs.com/demobobin/randpos_logicbricks.jpg
size - the size of the area where the objects will be placed(ex 20= 20 by 20)
obsize - the spacing of the “grid” that the object will be placed on(make it big enough to cover you’re object"
obnumber - the number of objects to be added
counter - leave this a 0
done - leave this a 0
height1 - minimum height that the object can be placed at
height2 - maximum height that the object can be placed at
(note: put both “heights” at the same number to have them all on the same elevation)
(note: all numbers are in blender units)
now, just put the name of the object you want added into the add object actuator
(note: it should be an empty that does/has all this)
this script is far from perfect and can be refined to be much more versatile. but i don’t have the time to do it right now.
i hope this helps
Thanks, this is extreamly helpful…