[SOLVED] Animation for Basic Ai not working

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

Im on it right now . Thank you two so so much, That really made my day :slight_smile: :slight_smile: :slight_smile:

2 Likes

Hii its me again but this time i have another problem :sweat_smile:
Do you know how i can make the Ai Rotate to the player and have a better Ai code into it?

Maybe my Basic enemy AI example project can help you. You can check the topic below.

1 Like

I’ll Check into it and let you know how thinking go after i take a look at the project. Thank you !!

1 Like


OKAY so basically this is the same error that happened to me before with the Mai Project i created, the animation works but the rotation goes backwards and away from the player

You can try to rotate the model of your character 180 degrees. For this your model need to be a child entity of the entity with the script.

You also need to apply an offset to your collision component so it get the right position.

How do i apply the collision component offset ? i can make you a editor because you know how to it and i’m not use how to do it but a did rotate the characters 180

You can find the settings on the collision component.

Does that solve the problem?

Its not working and i see the offset option but even how i use it it’s still not rotating when the gameplay starts

The collision offset has nothing to do with the rotation. I mentoined this because of the first picture you shared.

If you share the editor link of your project I can take a look.

1 Like

I just linked you to it - Overview - PlayCanvas 3D HTML5 Game Engine
Editor - PlayCanvas | HTML5 Game Engine

I created an example enemy in your project. It seems to work good now.

image

1 Like

Just tested it and now it seems to go very well as i had in mind !! :grin:
Thank you so much for your time :smiley:

1 Like