anim.setTrigger and anim.resetTrigger

Is there a clear example on this anywhere?

Hi @groupsjrBrianDouglas,

Check this example, how it handles jumping:

https://playcanvas.github.io/#/animation/locomotion

I had something similar but it never triggered the animation, Is there an image of your animStateGraph?

Thanks,

Brian

Hi @groupsjrBrianDouglas! Maybe your trigger is overruled by other states. If you share a link to your project, we can take a look.

There are no other states attached to it. Let me set up a demo, unfortunately at this point I canā€™t share the link for the more realized project. Iā€™ll get something up in a bit.

1 Like

@Albertos @Leonidas I am attaching some screenshots of my stateGraph. I have set it to use a bool which works but would prefer a trigger, seems cleaner. This was my solution to the trigger issue. Sorry got involved in some other issues. I am assuming the issue lies in my graph.



How do you set the bool?

In a script attached to a button

The result is that it stays in your Idle state? I donā€™t see anything wrong in your animStateGraph.

Exactly. It wonā€™t move to the attack state.

Did you check if the button is working as expected? Can I see your button script please?

Itā€™s a generic button so you can set the type and it forks on that. You can see the commented out Trigger call.

`ButtonControl.prototype.setState = function(bool, name) {
    if(name == this.entity.name){
        this.state = !this.state;
        this.entity.anim.setBoolean('State_b', this.state);
        if(this.type == 0){
            if(!this.state){
                this.app.fire('RpgControl:Speed', 0.1);             
            }else{
                this.app.fire('RpgControl:Speed', 0.3);
            }
            this.app.fire('RpgControl:Walking', this.state);
            return false;
        }

        if(this.type == 1){
           /*  if(!this.state){
                this.app.fire('RpgControl:Speed', 0.1);             
            }else{
                this.app.fire('RpgControl:Speed', 0.3);
            } */
            console.log("fire attack", this.state);
            //this.app.fire('RpgControl:TriggerAttack');
            this.app.fire('RpgControl:Attack',this.state);
            return false;
        }
    }
    
    
    
    /* this.nextPosition = position; */
};`

and the trigger call in the rpg had been

this.entity.anim.setTrigger('Attack_t');

Yes, but we donā€™t set a trigger anymore but a bool, right?

I see you start with this.app.fire('RpgControl:Attack',this.state);. Did you check the result of console.log(this.state); and can I see the other part that set the bool of the animStateGraph?

That is the boolean method, the trigger method ā€œthis.app.fire(ā€˜RpgControl:TriggerAttackā€™);ā€ never had that. As you can see it was commented out.

Iā€™m getting a little confused now. What problem are we solving? From the bool or from the trigger?

The bool works fine
the trigger was not firing
I would prefer to use a trigger. Itā€™s cleaner

Ah, alright. My bad.

How do you prevent the state is changing before the animation is finished, after you fired the trigger? Iā€™m not sure, but as far as I know there is no option right now to let the animStateGraph wait until the animation is finished.

Edit: This is only the case if you use Any State. If you donā€™t use Any State you can use exit time of the transition for this.

I use triggers here. The Editor setup is slightly different due to the use of the Bitmojis but you should be able to see how it is setup https://playcanvas.com/project/721733/overview/3d-bitmoji-library

Thankā€™s Iā€™ll check those out.