Hello, I made a script for BGE and put it on a cube. In the scene, there is a sphere, and I want the cube to get the position of the sphere and set it as its own position. How do I find other objects in the space from one object’s script?
You need to know the object name of the other object you are looking for. I’m going to assume that the cube is named Cube and the sphere is named Sphere. This script is running from the cube.
<i># find the Python controller that called the script</i> cont = GameLogic.getCurrentController() <i># find the object that owns the Python controller # in this case, the cube</i> own = cont.owner <i># get the current scene</i> scene = GameLogic.getCurrentScene() <i># get the sphere from the object list # you must put "OB" in the front of the name</i> <i>of the object you want</i> sphere = scene.objects["OBSphere"] <i># set the cube's world position to the sphere's world position</i> own.worldPostion = sphere.worldPosition
It won’t work. I get this:
Blender Game Engine Started Method ob.attr = val is deprecated, please use ob['attr'] = val instead. Followball:16 Method ob.attr = val is deprecated, please use ob['attr'] = val instead. Followball:16 Blender Game Engine Finished
I know what it means but what should I change
own.worldPostion = sphere.worldPosition