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.

https://playground.babylonjs.com/#A2LQK1#4

Maybe you can use navigation mesh and crowd agents?

2 Likes

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

https://playground.babylonjs.com/#A2LQK1#6

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

2 Likes

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.

3 Likes