[SOLVED] Animation for Basic Ai not working

It’s not the same as my code example.

@Kelvin_Riley2 Just one more thing that I have noticed to try to help out here.

There are also lines of code that are not terminated properly with a semicolon ; This will not execute. I have also noticed some extra commas etc. Or am I missing something maybe the wrong project link.

@Albertos

if (this.entity.anim.baseLayer.activeState != 'Walk') {
    this.entity.anim.baseLayer.play('Walk');
}

Was the example code right?

Yes, all signs are important.

The semicolons are from the original code, should i delete all of those extra commas and etc?

The problem is you have added some rules that should be in a statement, like my example.

:sweat_smile:Is there a way i could fix it ? i don’t know how to fix it by myself

Remove the current animation rules and replace them with my example code. You only have to change the animation names.


Like this or am i too stupid to understand???

Actually hold on, the code seem functional now

@Kelvin_Riley2 I see in your link above that it is possible you have not saved your code after you have edited it.

image

So as you make changes and apply what @Albertos is helping you with please save.

Yes I’ve saved the code after every Change i make

Can you please also show the line numbers on your screenshot? Then it’s easier to communicate about the code you shared.

I Believe the code is starting to working but the editor says the script has a error with the anim callback


2 Likes

@Albertos i’ll add you to the project

@Kelvin_Riley2 There are certain rules that need to be followed in Javascript. Here is what @Albertos is showing.

MaiAi.prototype.alert = function (dt) {
    this.AiDestination.copy(new pc.Vec3(this.AiTarget.getPosition().x, this.entity.getPosition().y, this.AiTarget.getPosition().z));
    this.entity.lookAt(new pc.Vec3(this.AiDestination.x, this.entity.getPosition().y, this.AiDestination.z));

  if (this.entity.anim.baseLayer.activeState != 'Idle') {
      this.entity.anim.baseLayer.play('Idle');
  }

};

You will need to correct this for each function. Notice that every function begins and ends like this.

EnemyAi2.prototype.fall = function (dt) {
//DO SOMETHING INSIDE HERE
};
2 Likes

Me and @Albertos have fix the script :slight_smile: Everything is right and functional now

1 Like

@Kelvin_Riley2 Yes I see that. Many thanks to @Albertos for his support. I think the animations need replaced with the inplace versions.

2 Likes