Facing opposite direction using lookAt

Hello!

I’ve been using Panda3D for two days, and I’m really enjoying it. I’m coding a simple game just to try some things, using some models in the Downloads section (ralph and the T-Rex)

Right now I have Ralph running around, something similar to the roamingRalph demo. I wanted a T-Rex to chase him, so I just added a second actor with the T-Rex model and then I tried a lookAt(ralph.getPos()) so it faced Ralph in a move task.

class TRex( DirectObject ):
    def __init__( self ):          
        self.trex = Actor("models/T-Rex/trex",
                            {"run":"models/T-Rex/trex-run"})
        
        self.trex.reparentTo(render)        
        self.trex.setPos(0, -80, 0)
        
        self.trex.loop("run")
        
        taskMgr.add(self.move,"moveTaskTRex")
        
    #Controls movement on each frame
    def move(self, task):
        
        self.trex.lookAt(ralphObject.ralph.getPos())        
    
        return Task.cont

But the T-Rex always faces exactly the opposite direction, as if running away from ralph. I also tried lookAt(ralphObject.ralph). Is it something in the model, like being the head in the negative Y, instead of the tail?

Thanks in advance!

Yes, that’s right, that model was modeled backwards. What can you do, most of those models were created by inexperienced students.

I’m pretty sure there’s a handy function that does what you want (ie, “lookAt, backwards.”) I just can’t for the life of me find it.

Until someone finds the simple answer, you can do the following:

Create a parent node for your T-Rex and reparent the T-Rex model to it.
Then rotate the T-Rex model by 180°
After that apply every other transform to the parent node.

So the altered code could look like this:

class TRex( DirectObject ):
    def __init__( self ):         
        self.trexParent = render.attachNewNode('trex-parent')
        self.trex = Actor("models/T-Rex/trex",
                            {"run":"models/T-Rex/trex-run"})
       
        self.trex.reparentTo(self.trexParent)       
        self.trex.setHpr(180° on the right axis)

        self.trexParent.setPos(0, -80, 0)
       
        self.trex.loop("run")
       
        taskMgr.add(self.move,"moveTaskTRex")
       
    #Controls movement on each frame
    def move(self, task):
       
        self.trexParent.lookAt(ralphObject.ralph.getPos())       
   
        return Task.cont 

i have a similar problem with my art assets … but mine also have inverted normals and wrong scale so using setScale(.001,.001,-.001) makes them face right be correct scale and have correct normals :slight_smile:

Thank you for the answers! I’ll use Legion’s solution until I have my own models :slight_smile: