GE Add Object & Trackto fail

hello

When I have an object use the logic edit object|add object, and then have another object use edit object | track to and give it the name of the object that I added, the tracking object always points to the original blender object, as opposed to the object created by add object.
Example: I have a cube that adds a sphere at a random postion (say 1,1,1), and a cylinder that uses track to (sphere), the cylinder points to 0,0,1, which is the sphere’s center outside of the game engine.
Is there a way to assign a unique name to a game object? Is there a way to trackto an added object? Are there any alternative methods for tracking?

Blender 2.49 | Python 2.6
Thanks a ton.

it used to be that, with python, you could change an object’s name, which might help… although ‘name’ is now a read only property.

My recommendation is to become a python guru, make a homemade track function like: vec = object.getVectTo(targetob)[1]
object.alignAxisToVect(vec,1,1)

as for finding the target object… try something like:
scene = GameLogic.getCurrentScene()
for obj in scene.objects:
if obj.name == ‘OBtarget’:
targetob = obj
break

That is, assuming you’re moderately comfortable with python. If you aren’t at all experienced with python, I suggest either learning some python or finding some other work-around

You can change the object’s name by pressing F9 and entering the object’s new name under “Links and Materials”…

Hi daeuss,

Using Python…


import GameLogic as g
scene = g.getCurrentScene()
objList = scene.objects

# ---- ADDOBJECT()
# Name of the object. On a hidden layer
add_this_object_name = "OBAdd_this"

# Add object from another one
from_obj = objList.get("OBSpawn")

# duration
obj_life = 150

# Add object
add_obj = scene.addObject(add_this_object_name, from_obj, obj_life)

and then use getVectTo(add_obj)
and align your tracker.

Tracking “add_obj” and not “OBAdd_this” should work.

Thanks all,

Almost: The method of targeting the object that you proposed has the same effect. The object it returns reports its original postition, not its game position.

cray: Your method of adding an object looks promising, I’ll give it a shot some time.

getVectTo & alignAxisToVect works like a charm, thanks for that suggestion.

I ended up using messages to transmit the position of my added object, then alignAxisToVect to point to it. Had to learn python, but it works.

you rock

for anyone interested

sending code:
text = str(obj.position[0]) + ‘,’ + str(obj.position[1]) + ‘,’ + str(obj.position[2])
GameLogic.sendMessage(‘pos’,text)

and then attached to a messagesensor on the receiving end:

import GameLogic

scene = GameLogic.getCurrentScene()

cont = GameLogic.getCurrentController()

sens = cont.sensors[“focusmarker”] #the name of the messagesensor

if len(sens.bodies) != 0:
text = sens.bodies[0]
pos = text.split(’,’)
for x in range(len(pos)):
try:
pos[x] = float(pos[x])
except:
print ‘pointing error’
pass
pointer = cont.owner
vec = pointer.getVectTo(pos)[1]
pointer.alignAxisToVect(vec,1,1)

setObject accepts KX_GameObjects (see http://www.blender.org/documentation/249PythonDoc/GE/GameTypes.KX_TrackToActuator-class.html#setObject).

If you can identify your added object, you can directly assign it to the TrackToActuator while running the game engine.
You can identify your added object with objectLastCreated of the AddObjectActuator (see http://www.blender.org/documentation/249PythonDoc/GE/GameTypes.KX_SCA_AddObjectActuator-class.html).

I hope it helps.