newby question

Hi at all,
i have some problems with animated actors.
there are some situation in witch, i don’t know wy, they realy dont want to move,
for example: in this code (that is a vere few modifiation of the first tutoria)
where is the error? why ony one panda walks?

import direct.directbase.DirectStart
from direct.task import Task
from direct.actor import Actor
import math

#Load the first environment model
environ = loader.loadModel("models/environment")
environ.reparentTo(render)
environ.setScale(0.25,0.25,0.25)
environ.setPos(-8,42,0)

#Task to move the camera
def SpinCameraTask(task):
  angledegrees = task.time * 6.0
  angleradians = angledegrees * (math.pi / 180.0)
  base.camera.setPos(20*math.sin(angleradians),-20.0*math.cos(angleradians),3)
  base.camera.setHpr(angledegrees, 0, 0)
  return Task.cont

taskMgr.add(SpinCameraTask, "SpinCameraTask")

for i in range(2):
  #Load the panda actor, and loop its animation
  pandaActor = Actor.Actor("models/panda-model",{"walk":"models/panda-walk4"})
  pandaActor.setScale(0.005,0.005,0.005)
  pandaActor.reparentTo(render)
  pandaActor.loop("walk")
  pandaActor.setPos(i*3,i*2,0)

run()

thanks in advance.

Hmmm… for me as a programming-nub it looks like you are calling 2 times a function and are binding it to 1 variable.

In that case even if you do see 2 pandas on screen because they are both bound to the nodepath, you can only access (propably) the second one because its the one you are catching with the variable you gave to it (“pandaActor”)

Regards, Bigfoot29

This should work:

import direct.directbase.DirectStart
from direct.task import Task
from direct.actor import Actor
import math

#Load the first environment model
environ = loader.loadModel("models/environment")
environ.reparentTo(render)
environ.setScale(0.25,0.25,0.25)
environ.setPos(-8,42,0)

#Task to move the camera
def SpinCameraTask(task):
  angledegrees = task.time * 6.0
  angleradians = angledegrees * (math.pi / 180.0)
  base.camera.setPos(20*math.sin(angleradians),-20.0*math.cos(angleradians),3)
  base.camera.setHpr(angledegrees, 0, 0)
  return Task.cont

taskMgr.add(SpinCameraTask, "SpinCameraTask")

pandaActors=[] #create an empty list
for i in range(2):
  #Add a new panda to the list
  pandaActors.append(
           Actor.Actor("models/panda-model",{"walk":"models/panda-walk4"}))
  # -1 points to the item which was added last
  pandaActors[-1].setScale(0.005,0.005,0.005)
  pandaActors[-1].reparentTo(render)
  pandaActors[-1].loop("walk")
  pandaActors[-1].setPos(i*3,i*2,0)

run()

Ok thanks lots for the help.
i have tried and it’s run.
but…
i can not undestend why:
it is true that i rebind the same variable, but it is because i (in my code)
do not need to work more on the actor…

i add little comments at any line:
pandaActors.setScale(0.005,0.005,0.005)
#an operation on the panda

pandaActors.reparentTo(render)
#render, you have to drow this actor.

pandaActors.loop(“walk”)
#actor, you have to walk

pandaActors.setPos(i3,i2,0)

actor, be in this position.

#after this line i do not need more to work on this actor, so i have no reason to keep a way to reach it directly peraphs i was thinking that was possible to ask to the render the set of item that it have to render, if i really need to make stuff like stops the panda.
(of course on the render is stupid but it will be reasonable to have a node pandaAll that keep all the panda and render all of them, and admit me to work on tham)

Now, for what strange reason when the render drow the actor he don’t see that it is setted as a walking one?
note that it is not picked by the garbage collector, because the render can render it, that means “reasonably” that the render have an internal binding to the panda actor. (probably in one array)

That means that if i want an actor with an animaction it have to be visible trought some path from the global namespace?
if it is:
1)why?
2) in which way is possible for the panda3dLibrary to decide when an object is in the global namespace and when it is not? all way that i imagin are quite slow…

thanks in advance.
Nael

Actors are not like NodePaths; Actor is a Python class, while NodePath is a C++ class.
Once you redefine an actor instance with pandaActor=Actor.Actor etc. you destroy the old python class, which contains the code that keeps looping the animation.

You might want to take a look at the source of Actor.py.

Uhm… i dont really understand your second question.

Ok, thanks i will go to read Actor.py
It will be the best answare to both the questions.