As part of the ETC course, I was tasked to build an interactive Virtual Reality world in two weeks with a team of two programmers and two artists. We decided to create an underwater world where the guest player can interact with fish.
n the world, the guest player can guide the fish around using hand-held VR controller. When two fish meet each other, they will form a group. Two groups of fish can also merge into one when they collide.
I encountered a few challenges when crafting the interactive experience with fish.
First of all, the fish should be able to follow the trace of the controller. Steam VR in Unity allows me to keep track of the position of the controller. I set the sample rate to be 1 sample point per second. So every second, I will record the position of the controller and save it into an array. I start to track the controller when the guest player pulls the trigger on the controller, and finish tracking when the trigger is released. I will then pass the position array to the fish and order the fish to follow the path.
Using iTween, fish can move in a smooth path and also orient itself to path when moving.
The next challenge is to organize the fish into groups. Due to time constraints, I need a simple and straightforward solution.
I figured out that I could make a 4x4x4 grid space that represents the space that a group of fish is going to occupy. Each grid can only keep one fish at one time, so that fish don’t collide with each other. I maintain a priority list. When a fish get into that space, it will occupy the closet grid to the center of the grid space. This approach ensures that fish group is always compact.
When a fish gets near to a group, it will be assigned to a grid in the space. A path between the grid and the fish’s position is drawn. The fish will travel along the path and become part of the group. After fish gets to its position, it will orient itself to the same direction as the rest of the fish in the group.
I once worried that placing fish in to grids may look very artificial. However, adding some random motion (float the fish up and down) makes the fish group look more organic.
Lastly, as the fish will travel with the group, we need to make sure the center of rotation is consistent at all times. By default, the center of the rotation is always at the center of the cubic space. However, there will be conditions when there are more fish on the right then on the left.
When fish group is making a turn, the fish near rear side of turn will move a lot faster than the fish in the inner side of the turn. Hence, we need to adjust the center of the rotation based on the distribution of the fish in the group.
I wrap the group with an empty game object, offset the position of the group with the reference of the average position of the fish in the group. This approach allows the center of the rotation to stay consistent.
The final result looks like this:
Virtual reality enables a lot of new experiences that traditional game platforms can’t provide. However, it also raise the bar of game development. While striving for new interactions and experiences, we also need to focus on details as they are now exposed to the guest players from all directions.
Fish used in this VR experience is modeled by Feng Rao, and you can watch the full game play here: