Changing position of actor children object

Hello,

I have one stupid question about panda3d.How can I change position of
my actor children object? Example, my actor is ship(with cannons) and
children object is cannon ball.

Sorry for my bad english and probably bad explanation!

Regards,
Veki

You can iterate through the children like this:

for child in actor.getChildren().asList():
  if child.getName() == "cannonball":
    child.setPos(whatever)

Or, more easily, use the “find” method to find a certain child immediately:

cannonball = actor.find("**/cannonball")
if cannonball.isEmpty():
  print "Did not find cannonball object!"
  exit()
else:
  cannonball.setPos(whatever)

In the music box tutorial, there is a demonstration of this.
We “find” the hinge of the gold Chest to make it open or close at will .

Note that for Actors subparts & joints (not childrens added after load time) , there may be some additional subtlety (to expose joints ) because actors hierarchy are optimized for animation. So all groups in the initial 3D model does not exists in the animated actor.

Hello,
Sorry for my slow reply.
Thanks for both answers! :smiley: Works fine but in this topic I want to ask another question that I tryed to solve with this changing position of actor children object.I’m trying to set that cannon ball follows ship on same
height until I press some button.If ship change heading, cannon ball have to change it too but around the ship. Here is my snippet of ship and cannon ball:

        self.brod=loader.loadModel("brod2.egg") #Actor - "brod"="ship"
        self.brod.reparentTo(render)
        self.EnemySetup()
        self.brod.setH(23)
        self.brod.setScale(.01)
        self.brod.setPos(0,0,0)   
        self.brod.setH(self.brod,90) 
        self.brod.find('**/+GeomNode').setH(220)
        self.topkugla1=loader.loadModel("models/topkugla.egg")    
self.topkugla1.setPos(self.brod.getX(),self.brod.getY(),self.brod.getZ()+35)
        self.topkugla1.setScale(39)
        self.topkugla1.reparentTo(render)

Here is also small gallery about my game:
http://www.v-programs.com/include/mg.html

Sorry for my bad english and probably bad explanation!
So if you have any idea…I would be very grateful to you!!!

Regards,
Veki