Proj2:AquaSim


Unfinished, Image reference:

https://docs.google.com/presentation/d/1uMfnLEqgX6pksed2YPGNiv8K_eMJGxkRHDKC5jJj...

In this project, I want to simulate an aqua environment where fish, as the agents, can navigate freely in the 3D space. The rule is small fish will look for food, and once a small fish gets a food, it becomes a big fish that the other small fish will try to escape from. 

So first I create a low poly fish model in blender because I want to scale up the number of fish in the env and I want to optimize the performance. 

I also rig the model and create a simple animation for swimming

The first rule I implement is target following. Many fishes are apawned at random location and some targets are spawned randomly as well.  The fishes will try to get the target. Currently the target is just an abstract location stored in a script, with no entity attached. The script will reshuffle the location every certain seconds.


So now the fishes automatically build the behavior of grouping, Fishes looking for the same target will cluster together.

But there is a problem. As time flies, the fish will overlap with each other so it looks like there are fewer and fewer fishes in the scene. 

To mitigate this problem, the next rule I implement is distance keeping. The fish will calculate a collision offset based on the mean location of all the fish entity within a certain range of sphere. The offset will add to the global target position which define the behavior of steering.

And it looks much better now.

So I think it's time to create an entity of food, locate at the target position. This is important because firstly it is visible, and also I need a collider to check if a fish hit(eat) the food. 

I add particle system above the entity to make it more visible. 

To implement logic after collision, I need to build a conplex system between the global target info manager, each entity of food and each entity of fish. Once triggered, the food will tell the manager to decrease the number of active food. When there is no active food, the manager will reshuffle the loation of food, move the food entity, and reactivate all of them. The food will also tell the fish that it get the food, and all the logic following is implement in the function Grow() in the fish entity.

The fish get the food, it will grow to be a predator. So I need to create a new body for the predator. I scale it up and make it red and darker. 

 

So once grow, the fish entity will switch its body by deleting the old one and instantiate a predator model attached to it. It will also rename it's body tag as predator for later logic. 

So we have different class of fish and we can create different state for different class. The state is simply whether it is a preditor and the sensing behavior is simply check whether there are food, small fish, or big fish surround, which will define the target and thus control the whole system. 

So here is an example of a big fish chasing a small one. The variable control the behavior.

Some more details:

The sensing sphere is larger for small fish than big fish. Different from the collision sensing, the chase and escape  logic find the closest entity. 

The small fish's max speed for its steering logic will increse when it's escaping. 

The big fish only survive for a while, otherwise a pair of fish might go to nowhere to be found.  So after its death, it will respawn as a small fish.

I found a ocean skybox online and add it to the lighting. I deactivate all the light source in the scene and adjust the emission of the fish body to make them visible. 

I also add a control script for camera movement. Initially I want to attach it to an object and let the camera follow it. The effect is not very good since it's hard to control the direction of camera, so I move it back to the camera.

And that's the whole implementation of project2: Agent: AquaEnv. Enjoy!

Get Proj2: Agents

Leave a comment

Log in with itch.io to leave a comment.