The second limitation is that the moment you start the bots begin chasing you. In a real game this isnt bad depending on the context. For example say your character reaches a reputation of negative 45. Now we want to spawn a bounty hunter to dispatch the character. We dont want the spawn point to be close but not really far. We want to add the illusion on long distance travel. So we would create the point close to the player and spawn the bot and have it immediately seek out the player.
For this tutorial we will address these two points. You will need the past code for this tutorial, the link for it is here: Chase AI
In Unity the up/down variable is 'y'. This will be used for our gravity. What we will do is check if the bot is grounded, if its not, we will take the my_Velocity Vector variable and adjust the 'y' value of it and set it to zero.
my_Velocity.y = 0;
Next make a new script and name it 'ChaseTrigger'. This script is straight forward, it will use an intrinsic function, a conditional and a boolean. This script will be accessed by the main AI script we will make.
This version is by far the fastest. All we need are two variables, a time to detonate: public float timeToBeginChase and a timer to be incremented till it reaches the threshold to detonate: public float timer. Copy the original Basic Basic AI script and add the following two variables in the heading.
Now in the Update() we need to update the timer variable and compare it to its detonation threshold.
The line: timer += 1 * Timer.deltaTime; increments the variable timer each frame. The variable is later compared in the line if(timer >= timeToBeginChase) if the timer value is greater than or equal to 5, then the bot will be triggered. Now compile, and attach the script to a bot. As always remember to set the fields of the script like above. The code for all three scripts is below.
Chase Triggered, and timed
Other methods of AI include gauging the distance between a bot and player, making judgment calls, "sight" and "sound". Maybe ill try and make a few for examples.