Forum rules - please read before posting.

Custom NPC animation

I'm hoping to create a scenario when an NPC approaches the player, and upon reach the player performs a custom animation like a stab or punch. The game will then end at that point. I've placed a trigger collider on the player. On cue, I have the NPC follow the player. When the trigger is entered, I execute this:

void OnTriggerEnter2D(Collider2D col){
        if (col.tag == "Enemy"){
            NPC npc = col.gameObject.GetComponent<NPC>();
            npc.StopFollowing();
            Animator anim = col.gameObject.transform.GetChild(0).GetComponent<Animator>();
            anim.SetBool("Attack", true);
        }
    }

When this runs, the animator quick attempts to change back to Idle, and the animation keeps flipping from Idle to Attack endlessly. I've tried switching the charState to Custom as well, that just makes the attack animation freeze on the first frame. Any suggestions on the AC side I haven't thought of?

JJ

Comments

  • Setting the charState to Custom before calling SetBool should do it - is your character using Sprites Unity for their animation engine?

    Sprites Unity Compex is often better when dealing with custom states / transitions, as AC won't play animations directly, instead relying purely on parameter values.

  • I've kind of reversed things a bit. I've put the trigger on the NPC and when the player hits it I'm running an action list from code, which seems to make it a bit easier to perform a custom animation. You are right, I was using Sprites Unity instead of complex.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.