How to create an enemy that tracks the player?

I finally want to add enemies to my game. I just can’t find a way for my enemies to track down players. Does anyone have any examples or tips?

My goal is to make the enemy track down the player and damage it once it has contact with the player.

Maybe you can use navigation mesh and crowd agents?

1 Like

Yes, thanks so much!
I didn’t really understand all of the parameters, so I read peoples’ code and tried learning a bit.

Could you help me find out why my enemy (agentCube) isn’t tracking the camera?

Adding @Cedric as he is the master of Crowd Agents (never used myself)!

I guess you will need to provide a PG, however.

Yes, please provide a PG :slight_smile:

OOPS I forgot to post it in there! I was rushing, sorry.

Here’s the PG

there was a log in the console warning the navmesh could not be greated.
You provided the ground mesh before it was created.

Fixed :

crowdagentstest2 | Babylon.js Playground


How do you view the console in PG? Learning that should solve some issues I might have in the future. (I feel so dumb for asking this lol)

press F12 in your browser and select the console tab. same hotkey for most browser.


Debug Javascript:

There are a lot of other points I didn’t know that one can do with the dev tool! :slight_smile: