0
$\begingroup$

I am working on a game in the blender game engine. I need to Position an empty, spawn an object at it, re-position it, and spawn another object. When I run my script it only appears to have activated once. I have recreated the scenario in another.blend file and the situation still persists.

Here is my code:

import bge

cont = bge.logic.getCurrentController()
own = cont.owner


actu = cont.actuators['SpawnCube']
own.worldPosition = [4,0,0]
cont.activate(actu)
own.worldPosition = [-4,0,0]
cont.activate(actu)

Running in the embedded player

$\endgroup$
0
$\begingroup$

yeah that is an issue when using Logic Nodes. I think some of them can only be activated once per frame. There is however a solution to your problem and its this:

import bge

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

own.worldPosition = [4,0,0]
scene.addObject('NameOfTheObjectToAdd', own)
own.worldPosition = [-4,0,0]
scene.addObject('NameOfTheObjectToAdd', own)
|improve this answer|||||
$\endgroup$
0
$\begingroup$

An actuator can be activated as much as you want.

Be aware it will run ONCE per frame when it was activated.

What you want is different. You want to manipulate the scene at the moment of executing the custom controller's code multiple times. Josip's Answer should be sufficient enough.

alternatively you can use the AddObject actuator (for setup the master object via GUI):

addObjectActuator = ...
addObjectActuator.instantAddObject()
addedObject = addObjectActuator.objectLastCreated # call that after instantAddObject() only

See BGE API

|improve this answer|||||
$\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.