Add Object onClick

I have a World model, where I use hitPosition data to determine where on the World model I’m clicking. I want to, onClick, add a model who’s name is stored in the world model properties (here shown as objectToAdd). If I replace (pX, pY, pZ) with “World”, the building I’m adding is added to the World’s center. I want to add the building at the place I’m clicking (pX, pY, pZ). But I’m not sure how to do this. Help?

When I MouseOver the World model


from bge import logic


cont = logic.getCurrentController()
own = cont.owner
mouseoverany = cont.sensors["MouseOverAny"]
own['pZ'] = mouseoverany.hitPosition.z
own['pX'] = mouseoverany.hitPosition.x
own['pY'] = mouseoverany.hitPosition.y

When I Left-Click


from bge import logic


cont = logic.getCurrentController()
own = cont.owner
scene = logic.getCurrentScene()


newObject = own['objectToAdd']
pX = own['pX']
pY = own['pY']
pZ = own['pZ']


scene.addObject(newObject, (pX,pY,pZ), 0)

Just set the position of the object after adding it.

obj = scene.addObject(newObject, own)
obj.worldPosition = [pX, pY, pZ]

Sometimes the simplest answers elude you. Thanks. :stuck_out_tongue: