Sportsball Month One
By Aaron Holowienka
Month one was an extremely busy month. I started the month by putting together the basic architecture of the entire engine with Jordan and once that was finished I jumped straight into the physics engine. At the beginning of this task I had pretty much no idea how to write a physics engine or what SportsBall actually needed. The one thing I had to go off of was that we wanted rigid body physics. The only game we had made before was in Unity and we were just like, “Let’s make rigid body dynamics, just like Unity”, so that is just how I started. After a few days of research and reading many articles on full rigid body dynamics, many of which were way to advanced for someone who has never really studied that kind of physics, I realized that our game does not need physics to be that advanced. At this point, I changed my strategy by figuring out what the most basic level of physics I need to get the results that SportsBall required. SportsBall needed balls to be able to be thrown and bounce off of things and that was pretty much it. So, I decided to use Euler’s method to move the balls around the world, standard impulse-based collision resolution against walls, and collision resolution based off of conservation of momentum for sphere-sphere collision.Step one for getting the physics up and running was just basic ball movement using Euler’s method. Then I moved on to getting the ball to bounce off the ground using hardcoded world boundaries. After having basic movement and resolution down, I moved into actual collision detection, starting with Sphere-Sphere and then doing Sphere-AABB. For the most part, things went relatively smoothly, with my biggest problem being resolving a sphere-AABB collision where a sphere’s center point got into an AABB during a frame. I ended up fixing this problem by rewinding the sphere’s position so that the center point was outside the AABB, then resolving the collision, and recalculating the physics with the rewound time and new velocity.
After getting the physics to a stable state, I moved on to doing the throwing. I had to calculate the ball’s spawn position by using the camera’s and the player’s positions to put the ball in a spot that looked like a person could release it at and have it go in a direction that would make sense to someone aiming with a third person camera. This wasn’t too difficult because the ball just spawned in a spot and went straight ahead. Things got more difficult when I moved on to adding curve to the ball. My initial thought was to just always push the ball along it’s local x-axis, but I quickly realized that the way I faked the ball’s rotation made its x-axis not at all what I needed to accomplish this. I then realized that I could get its local z by normalizing its linear velocity and its local y was always straight up, so I could calculate its local x by crossing these two vectors. Having accomplished this, adding curve to the y-axis was pretty easy. Next, I added slow-mo to the game when the player aims and then kept track of the mouse movements while aiming to apply a suitable amount of curve force dynamically based on the mouse movement. This was just an overview of all the things that I accomplished in this month and looking back I am pretty proud of the way things went. From starting with just trying to piece together an engine with very little code, to adding dynamic curve force to ball that’s controlled by a physics engine that I wrote, I think I accomplished a lot. I am certainly excited to see what else our team can accomplish in our remaining three months.
Comments
Post a Comment