Prototyping is essential to getting the feel of gameplay just right. Here are two prototypes I built for NanoDoc:
I used this prototype to figure out flocking algorithms, but it’s also a fun little toy to play around with. Basically, flocking is determined by 3 variables – Cohesion, Alignment, and Seperation. In the prototype, each “bird” acts independantly, based on the value of the three variables.
Cohesion – how close (positionally) a bird sticks to the average position of its neighbors
Alignment – how close (directionally) a bird sticks to the average vector of its neighbors
Seperation – how much distance a bird maintains from its neighbors.
By adjusting the weight of each of these variables, you can end up with some reallyl cool behavior.
Here are just a few screenshots of different settings:
Flock1: By default, with C, A, S = 1, there is very tight, jittery flocking behavior
There are a huge number of variations that could be generated from these three variables, and probably lots of cool behavior I havn’t even discovered.
The flocking algorithm could also be improved by have different birds use different settings, or allowing variable speeds for birds. Right now all the weighted values are normalized, and the vectors are multiplied by the speed. If there was some sort of “smoothing” of the speed, you’d end up with even more realistic behavior you see in nature.
The windows install is here: http://daydalus.net/GameDev/Prototypes/FlockTest.zip
The source code is on bitbucket here: https://bitbucket.org/tdonlan/flock-test/src
I used this prototype to figure out how the viruses would flow through the bloodstream in the game. I wanted to have naturalistic movement, and have the germs bump off each other, but not richochet around like billiard balls.
private Vector2 CheckOthers(Vector2 position, Vector2 Velocity)
for (int i = 0; i < game.balls.Count; i++)
//push away from the center
Vector2 direction = BoundingCircle.Center - game.balls[i].BoundingCircle.Center;
if (direction.X != 0 && direction.Y != 0)
direction *= game.CollisionVal;
Velocity += direction;
Each ball checks all the neighbors using circle collision detection. If there is a collision, the ball moves away. The key is to “soften” the direction to push the ball. Right now I’m using .8. This value could be adjusted. A lower value makes the balls “squishier”. A higher value makes them “bouncier”.
Windows Install here: http://daydalus.net/GameDev/Prototypes/BallTest.zip
Source code on bitbucket here: https://bitbucket.org/tdonlan/balltest/src