I was just wondering, is there a way to make an object that’s added in the game engine move to a specific location? Any help is appreciated.
This script will be attached to a Python controller with an actuator sensor. That sensor will have the name of your add actuator in it.
All you have to do is paste this into the Text Editor, then reference it, by name, into the Python controller.
The object with the controller needs to have 3 properties.
- x (float) = The new X location of the added object
- y (float) = The new Y location of the added object
- z (float) = The new Z location of the added object
That way, you can easily edit the added’s position.
Here is the script:
import GameLogic
cont = GameLogic.getCurrentController()
own = cont.owner
sens = cont.sensors[0]
act = own.actuators[sens.actuator]
obj = act.objectLastCreated
obj.worldPosition = [own['x'],own['y'],own['z']]
Hope it helps,
-Sunjay03
EDIT: Here is a blend in case you don’t get it: Example.blend (131 KB)