Compute the heading of an actor

I am using Panda3D as a playback engine for data. I have a list of X,Y,Z positions in an HDF5 file. I can position the actor in the correct X,Y,Z positions but am having trouble setting the actors heading.


...more code above...
            #gets current position
            prevPos = self.ralph.getPos()
            #gets next position
            currPos = Point3(self.positions[task.frame][0], self.positions[task.frame][1],self.positions[task.frame][2])
            #returns heading vector
            heading = currPos - prevPos
            print "Heading: ", heading
        except IndexError, e:
            print "End of positions"

What am I doing wrong?

Thanks in advance!

Perhaps NodePath.lookAt(x, y, z) is what you are looking for?

self.ralph.lookAt(self.positions[task.frame][0], self.positions[task.frame][1],self.positions[task.frame][2])

Great, it works with one exception :slight_smile: I have to adjust the heading after the call to lookAt():

currPos = Point3(self.positions[task.frame][0],    
NodePath.lookAt( currPos )
NodePath.setH(NodePath.getH() - 180.0)

The actor is heading away from the direction he is heading. What did I miss?

Thanks for your help!!

I would make sure that the place you want the actor to point is really in currPos. I mean, Maybe you are setting currPos to the last location in the playback list instead of the next? When the actor is at A, you would aim it at B, but if it is at B, you must aim it away from A to get the right effect, and I suspect that’s what is wrong.

I’ll give it a try, thanks again for the help.

Or perhaps your actor is modeled so that he is looking down the -Y axis, instead of down the +Y axis. This is a common problem, because people like to model actors so that they look them in the face in the modeling package, but that means the actor is looking backward–which is down the -Y axis.

In order to fix this, you can either turn the actor around in your modeling package (so that you’re looking at his backside when he animates), or you can turn it around in Panda by putting him under another node and setting a 180 degree heading on the actor itself, then using the parent node for your setPos() and lookAt().