I'm new to game development. What is a good algorithm to model the random flight of a fly? I've been looking at path-finding algorithms, but they don't give any interesting random behaviour.
|
|
Lévy flights or brownian motion should work. These are random walks where at each time step the insect moves a random direction and distance. They differ in what distribution the random variables are sampled from. The motion of hunting sharks can be modeled as brownian motion when prey is plentiful and lévy flight when prey is scarce. Depending on what you use it for, you might want to restrict their motion (to keep them near a specific part of a level) or limit the acceleration (to make them appear to have have more inertia). |
||||
|
|
I made something similar to this a while back for 2D movement, but it should be a similar concept, similar to the way a fly buzzes around.
This should create smooth acceleration, and it should be buzzing around in circles. In two dimensions, accdir would be either clockwise or counterclockwise, so it would be spinning in circles by adding or subtracting from the vector angle, changing direction every so often. In 3D, it might be a bit more complex. |
|||
|
|