flame-engine / radiance

This library is a collection of AI algorithms used in games.
MIT License
23 stars 3 forks source link

Added Separation behavior #40

Closed Perumallpardhiv closed 1 year ago

Perumallpardhiv commented 1 year ago

Added seperation feature, check it!

Recording :

https://user-images.githubusercontent.com/96647299/195695451-bffcef73-4d95-463e-a67c-a42bcb23cc1a.mp4

Thank you.

Closes #18

st-pasha commented 1 year ago

So, that's a good starting point, but now we need to actually implement the Separation behavior. This is a standard term in the literature, described in https://www.red3d.com/cwr/steer/gdc99/ as

Separation steering behavior gives a character the ability to maintain a certain separation distance from others nearby. This can be used to prevent characters from crowding together. To compute steering for separation, first a search is made to find other characters within the specified neighborhood. This might be an exhaustive search of all characters in the simulated world, or might use some sort of spatial partitioning or caching scheme to limit the search to local characters. For each nearby character, a repulsive force is computed by subtracting the positions of our character and the nearby character, normalizing, and then applying a 1/r weighting. (That is, the position offset vector is scaled by 1/r 2.) Note that 1/r is just a setting that has worked well, not a fundamental value. These repulsive forces for each nearby character are summed together to produce the overall steering force. See Figure 14:

separation behavior

So it doesn't mean you want to get away from other agents as far as possible (that would be Flee behavior), but rather avoid getting too much into other people's personal space.

In the README of this project there are links to other game libraries which have implementations of those behaviors -- you can check those for inspiration!