track to new added objects?

How can you track to a newly created object? When I track to an object the object tracking it simply goes to the position of the original object on a different layer. I want to track the newly created items. I was thinking that maybe the newly created items could be renamed with adding numbers and the tracking could add the numbers for each new object? I am sure there are better ways. Please help!?

python!!!

okay, so get this

edit object, add object actuators have a call which will return the object which was added [starting the frame after it was added, until another one was added]

this would usually be used to place bulletholes or something

but, you can do whatever you want with that object [just like if you detected it with a near sensor]

this includes tracking to it, but you can’t just put its name in a track to actuator, you need to generate the orientation matrix to track to it.

… and that is pretty much all there is to it. The generation of an orientation matrix from that vector you want it to face isn’t exactly trivial though, you’ll probably want to look for a bullethole script or how glu_lookat works or… yeah, I can’t really help you there

z3r)d or whomever else

Thanks for responding. I am not really following you. Which part of the bullet hole script? I am just starting on the newbie tutorials for Python so I understand a little more than nothing. I have looked at the bullet hole scripts but they are a bit ahead of my abilities. I am not sure which part I am suppose to be looking at. Is there someone out there that could walk me through this or give me more pointers or a sample? I am sorry to say that I still need more help!

I probably have a bullet hole script round here somewhere

#bullethole.py
#
# object properties
#	type	name	value	use
#	Int		ebhole	0		keep track of if I need to position a bullet hole still
#
# random note about implementation:
#  the gameblender python api give me access to added objects the frame after I trigger the actuator
#  so I have to react accordingly.  

from math import sin, cos, sqrt

# vector functions!!
def VEC_length(x):
	return sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2])
def VEC_normalize(x): 
	length = VEC_length(x)
	return [x[0]/length,x[1]/length,x[2]/length]
def VEC_cross(x, y):
	return  [x[1]*y[2] - x[2]*y[1],
			 x[2]*y[0] - x[0]*y[2],
			 x[0]*y[1] - x[1]*y[0]]
def VEC_min(x, y):
	return [x[0] - y[0], x[1] - y[1], x[2] - y[2]]
def MAT_trackvector(fw, y):
	if abs(abs(fw[2]) - abs(y[2])) < .001: #prevent gimbol lock
		y.append(y[0])
		del y[0]
	right = VEC_normalize(VEC_cross(y, fw))
	up = VEC_cross(fw, right)
	return [[right[0], up[0], fw[0]],
		[right[1], up[1], fw[1]],
		[right[2], up[2], fw[2]]]

cont = GameLogic.getCurrentController()
obj = cont.getOwner()
ray_sensor = cont.getSensor("ray_bullet")
lmb_sensor = cont.getSensor("fire")
add_bullet_act = cont.getActuators()[0]

# position the last added bullet hole
newobj = add_bullet_act.getLastCreatedObject()
if obj.ebhole and ray_sensor.isPositive():
	hit_pos = ray_sensor.getHitPosition()
	hit_norm = ray_sensor.getHitNormal()
	# woohoo!
	newobj.setOrientation(MAT_trackvector(hit_norm, [0.0,0.0,1.0]))
	pass
	newobj.setPosition(hit_pos)
	obj.ebhole = 0

# determine wether or not to create a new bullet hole
make_bullet = ray_sensor.isPositive() and lmb_sensor.isPositive()

if make_bullet:
	# I am making the bullet hole, w00t
	GameLogic.addActiveActuator(add_bullet_act, 1)
	obj.ebhole = 1

so, first of note is adding the bullet hole


cont = GameLogic.getCurrentController()
add_bullet_act = cont.getActuators()[0]
....
	GameLogic.addActiveActuator(add_bullet_act, 1)

this doesn’t need to be done in python

well anway, then on the next frame the script is pulsed:

from math import sin, cos, sqrt

# vector functions!!
def VEC_length(x):
	return sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2])
def VEC_normalize(x): 
	length = VEC_length(x)
	return [x[0]/length,x[1]/length,x[2]/length]
def VEC_cross(x, y):
	return  [x[1]*y[2] - x[2]*y[1],
			 x[2]*y[0] - x[0]*y[2],
			 x[0]*y[1] - x[1]*y[0]]
def VEC_min(x, y):
	return [x[0] - y[0], x[1] - y[1], x[2] - y[2]]
def MAT_trackvector(fw, y):
	if abs(abs(fw[2]) - abs(y[2])) < .001: #prevent gimbol lock
		y.append(y[0])
		del y[0]
	right = VEC_normalize(VEC_cross(y, fw))
	up = VEC_cross(fw, right)
	return [[right[0], up[0], fw[0]],
		[right[1], up[1], fw[1]],
		[right[2], up[2], fw[2]]]

cont = GameLogic.getCurrentController()
obj = cont.getOwner()
ray_sensor = cont.getSensor("ray_bullet")
lmb_sensor = cont.getSensor("fire")
add_bullet_act = cont.getActuators()[0]

# position the last added bullet hole
newobj = add_bullet_act.getLastCreatedObject()
if obj.ebhole and ray_sensor.isPositive():
	hit_pos = ray_sensor.getHitPosition()
	hit_norm = ray_sensor.getHitNormal()
	# woohoo!
	# set the orientation of the bullet hole
	newobj.setOrientation(MAT_trackvector(hit_norm, [0.0,0.0,1.0]))
	# set the location of the bullet hole
	newobj.setPosition(hit_pos)
	obj.ebhole = 0

at least part of the vector math I probably stole from shoot_the_bunny.blend in the blender gamekit.

so, well anway, essentially you will use a function such as or similar to MAT_trackvector to generate an orientation based on the vector from your object [obj.getPosition()] to the other object [newobj.getPosition()]

you would probably be better off writing most of [as in, pretty much everything but the vector functions] your code from scratch, instead of trying to modify this code.

Sorry to be so Python disfunctional but I am still struggling with this problem. If anyone has an example of how to get an object to track an added object, please send it my way!