What do you want to achieve?
I have an openworld ,well sized map, and I want players to getting chased by some AI’s if they don’t behave well.
What is the issue?
Issue Isnt that I don’t know how to script AI, Just the main Idea on how to accomplish a smooth and well performend gameplay with the enemys. Should I take pathfinding? Should I use humanoids? How many humanoids are O.k for performance ingame?
What solutions have you tried so far? Tried humanoids and simply raycasting, just doesnt feel right tbh.
For idle/wander most games just have linked nodes on which NPCs can walk. Some of them have a case function where the NPC will wait for a green light. The chase behavior is easily implemented with pathfinding.
You can also add action nodes like cover mechanics where the NPC will hide if the wall’s face is on the opposite side of the player.
To cancel a chase, find the path to the closest wander node.
Humanoids are a questionable choice for this. They would make the walking much easier, but they will also cause a low framerate. 10 at the same time per player would be optimal, but don’t forget to disable most states.
Well your somewhat in luck as I’m doing my A Level assessment on AI’s in a game environment so I can give you some insight as to how it works.
How to do it:
To begin with: Yes use pathfinding as your NPCs actually need to know where they are going. With this form of path finding you’ll need to update the AIs path frequently as the user will obviously be moving about constantly. This can in high amounts be heavy on the game however even a small iteration of about 0.5 seconds per path would be sufficient as for a large brunt of a chase the AI will take the same path. The only time you may want to change the AIs speed is when your in a close quarters environment OR when you are close to the player - this is so the AI takes the most efficient route to the player and not an old route which doesn’t lead to them.
As for humanoids - also a yes. Have some custom animations on them in order to make them less dumb looking and hook the path finding algorithm into the humanoids and tell them to chase the target to the destination. You should use 2-4 humanoids for this to simulate a real police situation but not too many that it ruins the game or becomes stupidly funny.
How would I execute this?
With a police AI it would have to come down to two important considerations:
“Do I want to make it realistic or do I want to make it more fun.”
If you want a realistic scenario then the AI should already be outside as police wandering about on an idle path, they can then be called - the only issue with this is when you have 20-200 player games - 80 NPCs? 800NPCs!?! Which is why this method only works in smaller games as you don’t want 800 Pathfinding AIs nor do you want 800 NPC policemen to have to wait.
The better scenario in my opinion is case made spawning - when they rob the store a randomized amount of 2-4 policemen spawn at a randomized distance and the chase begins, when the chase is over they despawn. This can be done on a simple button press which sets you as the target. Another good thing about this method is that if the 4 police get stuck and leave a certain radius they can be despawned and new officers can be spawned in order to keep the chase alive.
I would explain more but I’ve got a dentist appointment!
First off all Thanks alot for the huge respond.
My game is aiming to have 20 players max ( still need to see about performance from other stuff )
And the game is supposted to be fun and exciting.
I’ll try to use some pathfinding first, as It seems the easiest to beginn with.
Do you think, 20 Police AI with pathfinding will have a Huge performance drop? So its noticable to the players?
I was also thinking on maybe starting with a Helicopter AI that simply drops off police troops to the players destination. But I’ll try it out first! :))
So jeah , remaining questions: Do you think, 20 Police AI with pathfinding will have a Huge performance drop? So its noticable to the players?
I mean it depends on how much mathematics the AI has to do, if your using the pathfinding module only then no you will be fine with 20. You wouldn’t even notice it probably. Pathfinding is 100% the way forwards with this.
With the Helicopter AI you may want to consider it may not be an “AI” as for it to be an AI it has to demonstrate some kind of intelligence (which pathfinding does as its making an intelligent path). This would probably just be a recursive function unless it chooses the optimum location to drop someone off (which would be within radius of the player and not on top of a roof for example).
Also in order to make the AI you also need an end argument e.g. how do they stop pursing and this can be easily done by using either a on touch event or within radius event however the only bad thing about this is that if you lag the AI could catch you during your lag spike - this would not be your fault though as some people do have laggy internet.
Also if you want exciting the easiest way to someones heart is explosions and bullet effects, I was recently testing with my friends “the effects of bullets on excitement” and we found that when your being shot at and you can see where the bullet hit (and it sparks) its more exciting for the player.
Also a node system wont really work, you’d have to use waypoints instead and then a pathfinding algorithm to get to said waypoint. Not really sure why he also said that humanoids will lower your performance - players are more advanced then the AI and cause more problems for a server so not sure how 20 at the same time would be a drag.