I am making a FPS game and I need know how to make my bots choose switching weapons, attacking, retreating, hiding, which path to follow…
Please help
I have nothing except attacking when my player comes near to the bot, but the problem with this is that the bot run straight towards my player, so if I move behind a wall the bot keeps running towards me and not going around the wall, and I have waypoints for the bot. I need a tutorial, scripts, or a demo project/Game to help me.
I would suggest a raycast and if it does not have line of sight hit connection then to start “patrolling”. I do this with my bot by raycasting left first. If no obstacle in say 20 units I move left and continue patrolling until I get a line of sight raycast hit with my target and then go into pursuit mode. If an obstacle is less than 20 units left I scan right and use the same logic, then reverse. If that fails I get the new postiton of target which will alter from previous frame and eventually the bot will find an open area. It keeps the bot out of corners. It is “stupid” AI but if the bot can travel directly at your player then a little stupidity is a good thing. So I have one script with an Update that decides on raycasting and bot obstacle avoidance and a series of if conditionals to avoid as many raycasts as possible by setting conditions and then two functions. One for Patrol and one for Pursue which are triggered based on line of sight.
O’Reilly has a (dated) book called AI for Game Developers. While you probably won’t be ripping code out of it, it is reasonably well written and well structured in terms of learning the basics of AI.
It’s not the end-all and I’m sure there are many that could be offered to you…I just like the way the author progresses through things like Pathfinding, Pursuit, Evasion, Flocking, and Obstacle Avoidance as you mention etc. Each topic builds on the others, and the drawings and (although antiquated) screenshots hammer everything home.
To expand on the other poster’s comments, consider after a raycast hit from predator to prey…give more advanced predators knowledge of the prey’s velocity and heading vectors, and alter the pursuer’s behavior accordingly (think leading shots from an AA battery). As far as obstacle avoidance, the raycasting should also detect the wall you mention, and the pursuer would have steering forces applied directly proportional to its proximity to the obstacle, and so on…