Rotate a nodePath around itself


It is probably something simple. I looked over here in the forum and found some things that are similar to what I’m trying to do, but I wasn’t able to do it, even with those topics about rotating Roaming Ralf … So I’m looking for help!

I have a nodePath that is my Pacman. I want to rotate it around itself.

IF the pacman is like that


I want his eyes to be looking to the right. And if the person wants to move it to the left, I want it to rotate 180 degrees and now be like that


Because of that, I need the axis of the rotation to be like the Z axis, but with the origin point in the center of my sphere (the pacman)

How can I do it? I’m able to rotate with Hpr, but it rotates and changes its position. I just want to rotate it, without moving.

Tks a lot just for reading. You are hellping me a lot!!!

If you want the origin exactly at its center, then you should set it at the center from within your modeler.

Thanks for your fast response!!

But if I do that, will Panda3d automatically rotate it around its own center when I use the setHpr method?

Tks again!

yes, it will. alternatively you can set a relative center point as first argument in most (or even all) transform functions. like nodepath.setH(anothernode, 10)


If I understood it right, this new node will be like the center point. But I don’t know how can I put it in the right position (in the center of the sphere).

That’s not quite right. Setting a rotation relative to another node doesn’t indicate an alternate center point; what it does is specify the rotation in the other node’s coordinate space, which is really something completely different.

The way to rotate a model about a specific point is to create the model in the first place with that point at (0, 0, 0), as ynjh_jo said. If you didn’t create the model and you don’t have the ability to modify it, then you can achieve the same thing by using nested nodes, something like this:

dummy = render.attachNewNode('dummy')
dummy.setPos(cx, cy, cz)
model.setPos(-cx, -cy, -cz)
dummy.setHpr(h, p, r)

where cx, cy, cz is the point in the model that you want to rotate about.


I’ll try that David, tks again, man!

Then I’ll post the results.

hi papetti, i got the same dude before…i solve it simply by adding a line inside a condition, ad essempio maybe this help you:

def __init__(self):
   #First load your model  (lets say  "self.p")

   self.keyMap = {"left":0, "right":0}
   self.accept("a", self.setKey, ["left",1])
   self.accept("d", self.setKey, ["right",1])
   self.accept("a-up, self.setKey, ["left",0])
   self.accept("d-up, self.setKey, ["right",0])
   taskMgr.add(self.move, "Movement")

def setKey(self, key, value):
    self.keyMap[key] = value

def move(self, task):

    timing = globalClock.getDt()
    speed = 16

    if (self.keyMap["left"] == 1):
         self.p.setX(self.p.getX() + (timing * slowdown))
         self.p.lookAt(self.p.getX() + 100, self.p.getY(), self.p.getZ())

     if (self.keyMap["right"] == 1):
         self.p.setX(self.p.getX() - (timing * slowdown))
         self.p.lookAt(self.p.getX() - 100, self.p.getY(), self.p.getZ())

      return Task.cont

c = Yourclass()

That is how is made here :

Good luck.


Tks a lot for your response. Although I’m trying to set the center through the 3D-modeler (in my case, Maya), this can be very helpful in case I fail with Maya!


I asked Maya to show my center pivot, and it was set exactly in the middle of my sphere. But, when I import to Panda3D, the center point is a different one, much closer to the external circumference.

Does anybody know what I’m doing wrong?
Tks again!

It’s not Maya’s “center pivot” that matters, but the model’s origin: the (0, 0, 0) point within your model. To change the origin, you can apply a translation to the model, then freeze transforms.


David, I started fixing it and it is working. Tks again! In case I have another trouble with this rotation that I can’t solve by myself, I’ll came back to this thread for sure!