Tuesday, March 31, 2015

Blob Game Physics Project

This project was built off a previous physics project discussed here. So I already had some of the basics of a physics engine such as a physics object. The goal of this project was to create some sort of game using contacts, rods, cables, bungees, springs and mass aggregates. The first step was to create the contact system. This allows for contact generators to generate contacts and then a contact system to go through and resolve all of the contacts. For this game I went with a simple implementation of resolving the most important contact until all contacts were resolved or the loop went over the initial amount of contacts times two. From here it was time to create actual contact generators. The first one being the ground contact generator. This simply created a contact if the physics object went past a certain y value. With the ground contact it was important that our contact system handled something called a resting contact. We determine this by checking if velocity has changed. Once we determine it is resting we cancel out the velocity effects of the contact preventing the physics object from vibrating. That is pretty much all there is to the basics of contacts.

The next step was implementing the rods, cables, springs and bungees. This was pretty simple because we went over this in detail in class and had code examples in the book and the slides. From here we used rods to setup our mass aggregates. This was interesting because you had to be careful how you connected your rods or the object would not do what you expected. For this project I created a cube, a pyramid, and a tetrahedron.

Now that all of our physics was setup it was time to make the game. The first thing I did was add simple player movement to the player adding force in 4 directions based on WASD. Next I added a bungee cord to the camera and the player. I was able to get a pretty clean effect using a bungee cord over a spring and a significant amount of dampening. Without these tweaks a spring attached camera does not work very well at all. After the camera was working I decided to add collectibles and make them data driven. I made it so when you got into a certain range of a collectible it would attach a cable between you and one of the physics objects that was part of the collectible  shape. When a lot of objects are attached to the player it can be tricky to move around the game but that is just part of it.

Finally I decided to create a simple enemy AI. Once the player gets into a certain range of this AI it starts to follow the player. If it gets close enough it attaches a spring between the player and the AI. It then runs away from the player until it reaches the edge of the map. This makes it harder for the player to collect the objects needed to win the game.