ssatguru / BabylonJS-CharacterController

A CharacterController for BabylonJS
Apache License 2.0
215 stars 46 forks source link

PauseAnims() doesn't pause #62

Closed bigrig2212 closed 1 year ago

bigrig2212 commented 1 year ago

Hi all. I'm using pauseAnim() to play another animation (death animation).

All works fine - except that after the death animation is over, it reverts to the idle animation (but where none of the other animations will play). It does the same thing on Vincent model, so i dont think it's my GLB.

The only time it works is if i pause directly after doing cc.start(). Anytime later and it doesn't work.

I wonder, since pauseAnim only sets a property - does it need to do something more?

ssatguru commented 1 year ago

I think you found a bug

Like you said currentlly pauseAnim only sets a property. This just prevents the chracter controller from playing any new animations. But that does not stop it from continuing to play the animation it was already playing. Most of the animations are played in loop. I need to update the code for pauseAnim to also stop playing any current animation. I will work on that sometime this week.

bigrig2212 commented 1 year ago

Sounds good. I added this for the time being to handle my death anim, but i'm sure you'll come up with something more elegant/re-usable.

CharacterController.prototype.doDeath = function() {
        for (const property in this.agMap) {
            if (property != 'death'){
                this.agMap[property].pause()
            }
        }
        this.agMap['death'].play(false)
 }
ssatguru commented 1 year ago

@bigrig2212 I have updated the PauseAnims() in the last commit. The test files shows how to use them. Let me know if it works for you. Haven't published this to npm for now.

Also another thing which you can try is, set idle action to death anim. cc.setIdleAnim(agMap(death), 1, false);

bigrig2212 commented 1 year ago

Hi Ssat. It works, but there is something funny about it. If you call pauseAnims() and then later, resumeAnim(), the player's collider (or maybe y-pos) is impacted. The player starts falling through the ground.

Btw, i've added another animation for sword fighting (SwingRight). The tricky part is figuring out when the swing is done. I've added a case in _onKeyDown, to see if the "fight" key is down and if so, to play the Swing anim. Otherwise, to stop the swing anim. It works, but if you've got a moment at anytime, would be great to know how you'd add another animation/action that has a begin and end state. My way works, but seems messy.

   CharacterController.prototype._onKeyDown = function (e) {
        let isSwing = false;

  ...

        switch (e.key.toLowerCase()) {
            case this._actionMap.swingRight.key:
                this._act._swingRight = true;
                this.doSwingRight(); //this is where pauseAnims() is
                isSwing = true;
                break;

  ...

          if (!isSwing) {
                this.stopSwing(); //this is where resumeAnim is
          }
};