Let self look at Actor

Im trying to let self look at monster. Both are of type Actor. Heres my code:

        x3 = monster.getX() - self.getX()
        y3 = monster.getY() - self.getY()
        print "X3", x3
        print "Y3", y3
        phi = math.atan((x3 /  y3) / 180.0 * math.pi) #atan
        print "phi", phi
        phi = phi / math.pi * 180
        self.setHpr((phi, self.getP(), self.getR()))

But I doesnt work realy. Do you know why?

Of course there’s an easier way, because it’s… wait for it… Panda3D! :smiley:


If you just want to rotate the Heading:


Regarding of this matter,
I use lookAt frequently, but there is some incapabilities for the object direction.

If you use the smiley object, you’ll notice that the lookAt will cause the object to face backward instead of looking to the target.

At the moment i only have this workaround:

self.setH(self.getH()-180) #turn it 180 degrees to face the target

Other solution that i’ve found in the forum is to wrap it into a dummy node. The other is to scale it -1 which will flip it inside out.
But none is perfect for an animated actor. Is there a best solution for this?
Say something like this:


that would be very helpful :wink:


Unfortunately i already made all the animations set in the wrong direction. Altering all the animation won’t be a good solution.
That’s how i come with the turning idea. But that will cause the HPR integer increase abundantly.

I just tried ynjh_jo advise and turn the actor with that line, and it works like a charm!
All the animation set in a relative position to that direction.

Thanks for that.

Apologies for hijacking this thread, but is it possible to do that for pitch and roll as well?