Edit Object > "Track to" on a bone?

It’s posible?

Example:
I have a character with armature, but need the head look at some moving object.
I can’t use IPO/Action, because the target location is not know in advance.

P.D: The head and body must be one single mesh.

Thanks by your help :wink:

with a lot of math it could be done with armature.
take a look at: http://blenderartists.org/forum/showthread.php?t=74405&highlight=mouse+armature

Start by making two head armature animations, one horizontal and one vertical. Then you’ll need to calculate the angle from the head to the target. It isn’t that hard, if you know your math. I’ve made a similar script, if you don’t know how to do it I could give it a try. I’ve planned to make it public any way. After that you’ll just have to convert the angle to a float/integer property and have the head action run by that property.

Hope that’s any help for you

I’m not good in maths :frowning:

Yes please, would be very apreciate :o

Of couse, tha’s not problem :wink:

Sure! :stuck_out_tongue:

The easyest way is to use two armitures (makeing the head and body separate) the head would only be one bone with the object center at the base of the bone then you just rig it normally and give it track to.

hmmm… interesting, didn’t know you could use track to on armatures.

I’m a bit stuck with the code… and I don’t have time to finish it right now…

from math import *
cont = GameLogic.getCurrentController()
                                                                 #the sensors:
main = cont.getSensor("main").getOwner()        #the head object
skeleton = cont.getSensor("skel").getOwner()    #the armature
target = cont.getSensor("target").getOwner()    #the object the head will be looking at

#
pos1 = main.getPosition()
pos2 = target.getPosition()

#horizontal angle
if not (pos2[0]-pos1[0]==0):
    hangle = (atan((pos2[1]-pos1[1])/(pos2[0]-pos1[0])))
else:
    hangle = pi

if ((pos2[0]-pos1[0]) > 0 and (pos2[1]-pos1[1]) > 0):
    hangle = degrees(hangle)
if ((pos2[0]-pos1[0]) < 0 and (pos2[1]-pos1[1]) > 0):
    hangle = degrees(hangle + pi)
if ((pos2[0]-pos1[0]) < 0 and (pos2[1]-pos1[1]) < 0):
    hangle = degrees(hangle + pi)
if ((pos2[0]-pos1[0]) > 0 and (pos2[1]-pos1[1]) < 0):
    hangle = degrees(hangle + (2*pi))

skeleton.right = hangle*<b>frames</b>/360

where frames are the number of frame in the right-left animation…
The part that isn’t working is the angle in the verical direction… Maybe you should just use a script to convert the orientation matrix to degrees… I will pick it up again when I have time… maybe tomorrow, or the day after that

I know, but can’t do it on my current work (as said in my first post).

Sim88, thanks by your help :wink: