Basic enemy AI

A basic enemy AI that you can easily implant into your own project. That was the goal. Just add the enemy script to your enemy character and define the attributes. I’ve tried to keep the script as simple as possible. Try it in your own project! If you have problems or a feature request, please let me know here.

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

8 Likes

How do I prevent the enemy from going to the ceiling like this

You have rescaled you character.

image

The version you use is based on a character scale of 1. The new version has a character height attribute where you can apply the height of your character. (In your case 0.22).

image

But I dont want bullets

You can disable or remove shooting.

image

1 Like

ok

What is hud?

It’s the entity with the state text above the enemy. You can leave the attribute empty if you don’t want to use it.

Making the entity smaller can also have consequences for the obstacle detection. If I’m correct, the maximum distance to an obstacle is currently 2. If the enemy detect an obstacle to early, you can try to change this value to for example 1.

1 Like

So I added the height atribute myself exacly the way you had it and now it is really jumpy kinda what is the issue? PlayCanvas | HTML5 Game Engine

You can’t add it yourself as it is used on a lot of places in the script. I suggest to make a backup of your current script in another project and add the new version to your project. Then you can apply your custom changes from the backup to the new version.

ok, what I do not want the enemy to go up or down, cant I just remove fake gravity?

You can disable this.applyGravity(dt); in the update function of the script.

//this.applyGravity(dt);

would that fix the problem?

Yes.

1 Like

also I learned that basic enemy ai kinda works in the maze, but it only stays in that area, do you think that just adding multiple enemies around the map work work just a well as one pathfinding enemy?

You can do that. You can also try to increase the enemy range attribute.

how much bigger, it is at 40

It depends on the size of the map and the start location of the enemy. Default is 5. If the range is to high the enemy will move outside the map and that’s not what you want. I need to find a solution for that in the next update.

1 Like