object tracking another object on xy axis

I’m a complete noob at python and it seems that this can’t be done with logic bricks (am I right?) so I’m asking help here :

I have a sphere that I do not control, and I need a spot to have the same world position + 5 on the Z axis.

I guess the python script would something like this but I don’t know exactly : :no:

scene = GameLogic.getCurrentScene()
objList = scene.objects
sphere = getObject.objList(“Sphere”)
light = getObject.objList(“Light”)
light.worldPosition = sphere.worldPosition [0, 0, 0+5]

I don’t have any skills in python, if someone could just check the script and repair it the best possible. :spin:

(sorry for the bad english)

first, you need to import GameLogic, and objects is a clist
it would be like:

import GameLogic
scene = GameLogic.getCurrentScene()
objList = scene.objects
sphere = objList[“OBSphere”]
light = objList[“OBLight”]
light.worldPosition = [sphere.worldPosition[0],sphere.worldPosition[1],sphere.worldPosition[2]+5]

remember to check the blender console for python errors and print statements
edit:sorry, copied an error from your script

Also…

Can’t you just parent the spot (I assume you mean spotlight?) to the sphere? That would have the same effect with no scripting required. To parent, select the spotlight, select the sphere, and hit ctrl-p. Now when the parent moves, the child (The spotlight) does as well.

-Sam

@ facundocouzo : mm… this does not seem to work. in the console it says getObject not defined… :frowning:

@ TheSambassador : well it’s a sphere, so if I parent the spot to it, and the sphere rolls, the spot rolls too and I don’t want that… :rolleyes:

So do vertex-parenting instead.

Select the light, select the sphere, hit Tab to go into editmode, then select a vertice and hit ctrl-p. Vertices don’t have any orientation, just a position, so your light will simply move with the object and won’t rotate.

For best results, create a vertice at the very center of the object and parent the light to that.

oh thanks Sambassador!
worked perfectly
I didn’t knew that function :smiley:

(now I just need to know how can I modify the thread title to put a [solved] in it)