AI for FPS game

Is it possible to create bots in a playcanvas FPS game? I am working on an FPS game and I want to implement simple bots that spawn around the map and disappear when shot at, but I’m not sure how.

Hi @Xcyptionz and welcome!

Yes, this is possible. You can use a raycast to detect te player and maybe you can use a raycast to shoot on the AI as well.

I created a basic enemy AI example project where I use several methods to get a stable AI. You can use it in your own project or check how I did it.

I’m kind of new to playcanvas so I’m not really sure about how to implement it into my game. Do I just create an enemy model and apply the script to the enemy? Do I also have to create the bullet model for the ai, because I saw that the ai in game was shooting something.

Yes, that’s correct.

You need to recreate or copy the enemy entity.

This is optional.

you might want to also look into something like this depending on your programming skills

I created the enemy capsule and added all the components and scripts, but the ai doesn’t work like it does in the example project.

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

I already noticed that some components are disabled. (As far as I remember only the Anim component is optional, so you can leave this disabled). Also the rigidbody should be kinematic instead of static. There also seems to be a large offset between the enemy entity and your model. Make sure your model has to correct position and only move the enemy entity to relocate the AI.

Some of the components are disabled because I just added them before taking the screenshot. There’s one that has everything enabled and doesn’t work. Here is the editor link:

It looks like you are trying to create multiple enemy entities with the same enemy parent.

This is not how it should be.


Every enemy model need it’s own parent entity with the enemy script.

Please take a look at the hierarchy of the example project.


I think you can also copy the enemy entity from the example project.

Thank you very much for the advice. The enemy in my game can move now. However, it doesn’t track my player. Is it because the code is made to track a specific character which isn’t in the game? Should I name my fps controller something else?

It also doesn’t shoot anything, so I assume I should also import the bullet model and the bullet code

I pasted the “player” code onto my first person player model, and it still doesn’t track me. It also kind of glitches my screen out.

Targets need ‘Target’ tag. You can add a tag in the upper right corner of the editor when you have selected the right entity.

Yes, that’s correct. There need to be an available bullet template for shooting.

I added a new bullet template from the example game but it doesn’t shoot. I did it by adding instance and then selecting bullet. Also, how does the player health system work?

The entity need to be part of your assets and should have the name Bullet. I think you can easily copy and paste the Bullet template to your asset panel (lower middle part of the editor). Also make sure the attack distance of the script attribute is correct.

I’m trying to fix a problem where it says that bullet is defined multiple times but I can’t seem to find the asset I’m supposed to delete.

You can use the search option for this.

One script is in your Assets folder and the other script is in your Scripts folder.

1 Like