Hello everyone!
I am making a 3D game where the player has to catch rabbits.
Currently, the rabbit’s AI behavior is implemented using FSM, and navigation is done using NavMesh.
Now, when the rabbit notices the player, it simply runs in a straight line in the opposite direction. I would like to add an algorithm that simulates random yaw during the escape to confuse the pursuer. An example of random yaw is in the picture:
Lotsa ways… simplest is probably as follows:
-
get the vector “away” from the player (subtract player position from rabbit position)
-
rotate it a random amount (such as from -60 to +60 degrees?)
-
set that as your destination
Now periodically do that, say once every half a second or so.
Alternately you can also wait until the rabbit has arrived at each destination before rechoosing.
You can also maintain the initial desired “away vector” as a reference to ensure your rabbit doesn’t drift off course in his evasive maneuvers, if desired.
Alternately you could even just choose positions offset laterally from the away vector.
Also wanted to add about this:
because it’s super-simple but not always obvious.
if you have originalVector
and want to rotate it by angle
degrees, this rotates it around the Z axis:
Vector3 rotatedVector = Quaternion.Euler( 0, 0, angle) * originalVector;
You can get orientations around any of other axes (x,y), or use Quaternion.AngleAxis();
to get a rotation around any arbitrary orientation.
thanks for the idea, i will try this method