5
$\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$
2
  • $\begingroup$ Why can't you just have the empty create the object at its own position.? $\endgroup$
    – ruckus
    Commented Mar 5, 2015 at 16:20
  • $\begingroup$ That works just fine for me, but the question is how do you do that? $\endgroup$ Commented Mar 5, 2015 at 20:31

2 Answers 2

9
$\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$
4
$\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$
1
  • $\begingroup$ 0,0,0 is a vectore for a rotation matrix. $\endgroup$
    – Yvain
    Commented Mar 26, 2021 at 22:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .