Enemy Animation does not work

Hello, Im using the Basic enemy AI and will add animations. But I cant make the walk animation play, only the Idle animation works on enemies.

https://playcanvas.com/project/1060202/overview/trial

The issue is that your code in the updateAnimation function isn’t being called

image

// Prepared function to apply your own animations
Enemy.prototype.updateAnimation = function (dt) {
    if (this.entity.anim && this.entity.anim.enabled) {

The enemy script is on entity Enemy1 but the animation component is on Enemy child entity.

So the check you have in the updteAnimation function is never true because it is checking for an anim component on the Enemy1 entity.

That’s what I did on Enemy 2, still does not work, even the idle animation. :frowning:

There are several issues with Enemy2

  1. The anim component is disabled:

  2. As the anim component is no longer on the root of the model hierarchy and instead on it’s parent, you need to set the Root Bone on the anim component to reference the correct Entity to use as the model root.

  1. The code in enemy.js was using the wrong parameter. walk should have been Walk
this.entity.anim.setBoolean('walk', 1); 
// Should be
this.entity.anim.setBoolean('Walk', 1);
  1. There’s some test code that had to be removed. I commented this out
if (this.entity.anim.baseLayer.activeState != this.enemyAnimation) {
    this.entity.anim.baseLayer.play(this.enemyAnimation); 
}

Here’s fixed fork: https://playcanvas.com/project/1061448/overview/f-trial

1 Like

The original script is from the Basic enemy AI example project, that also has an Anim State Graph prepared. That script is tested and working as long as the setup is correct.

https://playcanvas.com/project/870482/overview/basic-enemy-ai

1 Like

Thank you!!