How would I have an enemy NPC not follow the player into water?

So I have an enemy that uses PathFinding, it works well except one issue, I don’t want players to be able to lure the enemy into water, this gives players an advantage over the NPC because my NPC doesn;y attack in water.

4 Likes

So, one viable solution that you could try is, when you are computing a path, send a ray downward from each node and check if that ray has hit water, if so delete that node. This should stop the Npc from being able to go into water

3 Likes

Add some invisible borders to the water, then either player and NPC can’t go into the river. :wink:

Put in invisible borders so players can’t bait NPC’s to get into the water.

1 Like

Currently only two solutions come to mind:

  • Solution 1:
    You can use a part that you call “PART” and if that NPC gets too close to its radius or touches the part, you make it change the direction. This can be done either through finding the Magnitude and its space between the NPC and “PART” or using Touched events (script.Parent.Touched: Connect() etc).

  • Solution 2:
    As @Jaycbee05 has stated above use pathfinding to find how close your NPC is close to the water and keep sending rays to calculate the distance until they must change directions or respawn.

  • Solution 3:
    If something comes to mind I will add it here.

I hope this has been helpful for you, let me know if you would need any further help.

2 Likes

You can use collision groups and have a set of invisible walls that collide only with NPCs.