Only the last model's animation is active

Hello,

When I load 50 walking panda models (that come by default with the installation) only the last model gets animated !

Here is the code -

from direct.showbase.ShowBase import ShowBase
from panda3d.core import loadPrcFile
from direct.actor.Actor import Actor
from panda3d.core import Vec3

class Application(ShowBase):
def init(self):
loadPrcFile(“PandaGame.prc”)
ShowBase.init(self)

     for i in range(50):
        self.pandaActor = Actor("panda",{"walk": "panda-walk"})
        self.pandaActor.loop("walk")
        self.pandaActor.setPos(Vec3(i*25,-40,0))
        self.pandaActor.reparentTo(render)


    self.cam.setPos(0,-400,6)

Can anybody tell me how I can animate all 50 of them ?

Hi,

What is happening, from just reading your code there:

You are losing the reference to all the other “pandaActor”'s that you are storing in the variable self.pandaActor

that’s why only the last one is animated, you need to keep them in different variables, or just keep reference to them (add them to a list)

Try this bit of code in place of yours:

self.pandaActors = [] # for storing references
for i in range(50): 
    pandaActor = Actor("panda",{"walk": "panda-walk"}) 
    pandaActor.loop("walk") 
    pandaActor.setPos(Vec3(i*25,-40,0)) 
    pandaActor.reparentTo(render)
    self.pandaActors.append(pandaActor) # Store the reference

Hello powerpup118,

That was just brilliant of you. Your advice just solved the situation so elegantly…thank you.

Thanks and regards,

Juggernaut

Hello powerpup118,

That was just brilliant of you. Your advice just solved the situation so elegantly…thank you.

I am new to Panda3D and so to Python. So I am playing with the engine so that I learn both Panda and Python by heart before I commence upon a project.

Can you please tell where is the - panda3d.core located in the file/directory structure - I was not able to find its location physically. The other classes - “Showbase” and “Actor” that I imported is located within the “direct” sub-directory under the Panda3D installation tree.

Thanks and regards,

Juggernaut

ShowBase and Actor (and all of the modules under direct) are written in Python. All of the classes in panda3d.core (and all of the other panda3d.* modules as well) are written in C++. You’ll find them in panda3d/panda/src/*.

David

Hello David,

Thank you for your reply. I now understand why the Netbeans 7.1 python auto-complete feature does not work for the - panda3d.core.* classes, since they are written in C++ they are linked at run time by the panda3d.py file located at the root directory of the Panda3d installation.

Please correct me if I am wrong.

Thanks,

Juggernaut

That’s correct. There was another thread recently about the problems of auto-completion; the topic comes up from time to time.

David