4
$\begingroup$

I plan on building a game where enemies are randomly generated throughout the game. I plan on using an empty to run a Python script where it will add a predefined object at a given position (using random.randint to place them randomly around the map). Is there a specific Python command where I can say something like "Create this object at this given x,y,z position"? If so, can you please tell me what it is and how to use it? Also, what is the difference between a Module and a Script in the Python controller? Thanks so much for your help!

Alternatively, is there a Python function that sets an object's X,Y,Z coordinates? If so, the empty can jump around randomly dropping enemies off at it's position.

$\endgroup$
  • $\begingroup$ Why can't you just have the empty create the object at its own position.? $\endgroup$ – Scalia Mar 5 '15 at 16:20
  • $\begingroup$ That works just fine for me, but the question is how do you do that? $\endgroup$ – Anson Savage Mar 5 '15 at 20:31
8
$\begingroup$

Move emitter to desired location

If you move the emitter (with whatever method you want) before adding the new object will be added there.

Move added object to desired location

You let the emitter create the object at one place and move it later (even in the same frame) example:

import bge

scene = bge.logic.getCurrentScene()
object = scene.addObject("Sphere","Sphere")
object.worldPosition = [1,1,1]

to find out more about module/script mode please have a look at the BGE Guide to Python Coding

$\endgroup$
3
$\begingroup$
    spawn.instantAddObject()
    obj = spawn.objectLastCreated
    obj.worldOrientation = [0 , 0 , 0]

where spawn is defined with spawn = c.actuators["spawn"] when "spawn" is add object actuator and [0 , 0 , 0] are coords

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.