object spawning

Quick question on the addObject function, is it possible to add a vector to specify where you want the new object to be spawned at instead having it appear at the object with the spawning script? I know you could simply move the new object immediately after it is spawned, but what do i do if i want to, say, spawn multiple identical objects from the same spawn-er at different locations at once?

EDIT: i will be leaving shortly after posting this and will be unable to reply for several days. i will read any replies when i return

You could use a for loop in a python script to move your object to different places and spawn objects.
for example:

for x in <count>:
own.worldPosition = <newVect> #with whatever algorithm you use to set a new vect
own.addObject(<xxxxx>)
if x == <count>:
break #you may not need this, but I like to include it anyways

Yup, MichelleSea has it. You just dump it all in a loop. I’d probably use a while loop that counts up.


I = 0
MAX = 20
while i&lt;MAX:
    new_obj = bge.logic.addObject(...)
    new_obj.worldPosition = vect
    i += 1

If it helps, I’ve noticed that loops do things almost instantly, while if you use if statements to manually count up and add, it takes a little while longer.

? It all runs inside a single frame. So, yeah, what!?

what I mean is, if statements can only run one iteration per logic tic, whereas loops do however many iterations are required as stated in the declaration. Or maybe, that’s just how I’ve been doing it.

^ That is how for loops (and while loops) work for everybody.

As a point of good code practice, this is rather un pythonic, as python has a range object for this purpose.

Doesn’t it run in less than a frame, technically (results only visible at the next frame)?

You can do things faster in the background by doing something like this:


while True:
    #do stuff
    break

Please look at the API to see the available arguments … it is not possible.

I do not see a problem with this method. Maybe you discover Physics issues.
What about: Move the emitting object before adding the new object? It is usually an empty and does not effect Physics. If it is not why not use an empty?