Animation Freezes in walking cycle

Hi guys, sorry to bother, but I’m hitting my head against a big problem that showed up since I switched from v1.5.4 to v1.6.2

Here is the task that moves my “Player” class.The self.model is an Actor with many animations; I designed it so that it has 4 main states: jumping, attacking, paused, and normal (this one doesn’t define a variable).

Jumping is obtained adding vertical velocity to the CollisionHandlerFloor that controls the self.model Z.

    def move(self, task):

        if self.HP<=0:
            return task.done

        #camera handling (if mouse is on the window)
        if base.mouseWatcherNode.hasMouse() and not self.isPaused:
            #base for the calculations
            if anim[0:3]!="atk":
            #"landing" check
            if self.floorHandler.isOnGround() and self.isJumping:
            if mPos[0]>=.998:
      , 2,
            elif mPos[0]<=-.999:

            data=Functions.castCam(self.R, Hz, Hy)
  [0]+data[0], startPos[1]+data[1], 
                                  startPos[2]+data[2], -Hz, Hy, 0)
            if self.isAttacking:
            elif self.isJumping:
                self.model.setPos(self.model, self.step*globalClock.getDt()*self.speedValue)
                self.model.pose("run", 1)
                self.step=Vec3(0, 0, 0)
                if base.mouseWatcherNode.isButtonDown(KeyboardButton.asciiKey("w")):
                if base.mouseWatcherNode.isButtonDown(KeyboardButton.asciiKey("a")):
                if base.mouseWatcherNode.isButtonDown(KeyboardButton.asciiKey("s")) and self.step[1]==0:
                #elif base.mouseWatcherNode.isButtonDown(KeyboardButton.asciiKey("s")) and self.step[1]!=0:
                elif base.mouseWatcherNode.isButtonDown(KeyboardButton.asciiKey("s")):
                if base.mouseWatcherNode.isButtonDown(KeyboardButton.asciiKey("d")):
                if self.step!=Vec3(0, 0, 0):
                    self.model.setHpr(180-Hz, 0, 0)
                    self.model.setPos(self.model, self.step*globalClock.getDt()*self.speedValue)
                    if self.step[1]<0:#this checks if the player moves forward
                        self.model.setPlayRate(1.5, "walk")
                        self.model.loop("walk", restart=0)
                    elif self.step[1]>0:#this checks if the player moves backward
                        self.model.setPlayRate(-1.2, "walk")
                        self.model.loop("walk", restart=0)   
                    self.model.loop("idle1", restart=0)
        return task.cont

The problem I’m getting is that when the model is moving forward, the “walk” animation is played only once, the freezes as in self.model.pose(“walk”, 1).
Instead, when it’s playing backward, the problem never shows!
Also the idle animation freezes after 1 loop.
A little variation, sometimes it runs fine for 3-4 loops, then freezes to death.Playing attacking anmations or performing jumps doesn’t remove the problem.
I tried to see if the problem was in the animation: I exported the model from Blender with chicken both R56 and R71b, same show.
But, I noticed that putting

self.model.setPlayRate(-1.2, "walk")

in the moving forward animation removes the freeze.

So: if an animation is looped forward, it freezes, if backward it’s fine.

The problem however may be in my code, for if I use the Ralph model with its own animations, the freeze shows up no matter what.

Any help is appreciated

It’s surprising that your code seems to be basically calling:

self.model.loop("walk", restart=0)

every frame. That’s technically legal according to the definition of loop(), but it’s an unexpected thing to do, and it doesn’t completely surprise me that the animation code might not handle it gracefully.

I’ll look into the underlying problem, but in the meantime, you should probably modify your code so that you only call loop() once each time you change state, but don’t call it again every frame.


Thank you very much!
I changed the design of the task as you suggested and the problem is gone.
However, this will make my state-changes a hell of if statements…
Careful design!