Showing posts with label Havok Physics Engine. Show all posts
Showing posts with label Havok Physics Engine. Show all posts

Tuesday, 18 February 2014

Havok Collisions


 Initial Implementation

           When we found out that we had to use The Havok Physics Engine for collisions, we heard that we had to use the abstract class: hkpContactListener. From here we fiddled around with it in the Havok Sdk, until we had the bare bones of what we needed.  For this to work we needed to initialize the contact listener first, by giving it 2 rigid bodies which it must search for a collision between, this would be an issue I’ll explain later. Once that is done, the contact listener must be attached to one of the 2 rigid bodies in the initialize function.
           How Havok handles it after that I do not know, however there is one function I can call to check if the 2 rigid bodies have collided. This function is the contactPointCallBack function, which is a virtual function so we can redefine it. This way in our game we have it so that we can set what the function does, which in our case sets a Boolean value for hit to be true.

 

 Issue 

The issue with this is that the only one object will know if it has collided with the other. For example if the listener was attached to the bullet, and the bullet collided with the enemy, only the bullet would know that it had collided with the enemy. The initial response I had was that I should just add another listener for the Enemy for that bullet, but that would not have been preferred.
    Figure L5
Looking at my initial thought diagram (figure L5); this would be one heck of a tangled messed if I did it that way. First, every enemy would have to check every bullet and the same vice versa. This is highly problematic because we wanted to have special attributes per bullet, so the bullet and enemy would have to communicate at some point. Another issue is that the when a new bullet is added, existing enemies will have to add another listener for that bullet. Finally when the enemies/bullets despawn, how do I know which ones to stop checking for in the opposite class?
 

 Solution

           Thinking about these problems, I though the only solution is some form of reference to the object it was searching for! To do this I initially had to decide which object will be referred to and which objected will have the listener.  The answer was simple; the bullet would have the listener, while enemies will be referred to. This is because no new enemies will spawn within the lifespan of the bullet (3 seconds or hitting another object), unless its end of a round.  
           Doing this meant I had to modify the listener class to take in a pointer to the enemy. This would modify the bullet manager to take in the enemy vector, so that I can get the pointers of all the enemies in the scene. Once that was done I had an array of bullet listeners, one for each enemy, each initialized in their own function (figure L6). The bullet will have to check the listener if it got hit, using a Boolean. With this when there is a collision, we can now have the pointer to the enemy call its hit response function, allow for more logical and easier to read code! Figure 6

Wednesday, 25 September 2013

Battlefield3/Frostbite 2.0+ Havok(physics engine)




One of the first demos I played on my PS3 was 2008's Battlefield:Bad Company, and I LOVED IT! Not only was there a fun atmosphere, a great multiplayer, with big maps, classes and vehicles. Although nothing came close to experience the beautiful frostbite engine's destruction for the first time. In its debut game, the frostbite engine did destruction that few other games could do in its time. Today its one of the most powerful engines in the industry, and a engine of choice for Electronic Arts.
To my surprise this powerful engine uses Havoc to handle all of its crazy physics. The Havoc physics engine widely used in the gaming industry and is used as a middle-ware for physics. This blog will focus on Frostbite version 2.0, which premiered in the highly popular game Battlefield 3.

Battlefield 3 One of the more popular shooters of today, mostly due to its large scale battles of its multiplayer. These matches can reach up to 64 players, and take place in maps up to 5 Kilometer square. The player has access to many gadgets, to the dozens of vehicles, and a ton of guns, all spread out over 4 special classes. With-in the sqauds of 4 teamwork is encouraged, and makes the game fun with friends.  One of the game changing events, is the destruction featured in majority of the buildings.

Havok – Havok is only used for physics (and not cloth physics) ever since Battlefield bad company 2, since the animation is using the ANT systems from EA’s sports franchises .

Wall debris 

Whether it be just a simple pillar, to a full concrete wall, you will see chunks of it fly off when you shoot at it. This is especially true if you fire a rocket at a wall, and the debris will fly outwards from the explosion. Sometimes of the debris will be rotating outwards based on the centre of the object, and where the force is applied. Some debris will hit the group on its side, and roll away until it stops on its side. With this, just shooting a simple tiled wall can be graphically amazing, just look at the gif below.

Whole buildings 

When the whole building collapses, you can see every bit of wall crumble. Like above, you can see rubble tumbling outwards from the building, however sometimes the rubble will stay inside the building. The roofs will instantly lose support, and being accelerating the ground. Also when the roofs will split and rebound off the rubble, depending on how much rubble is already on top. Seeing a building collapse in battlefield was a sight for sore eyes.

“Bullet drop” for missiles and projectiles 

With the concept of bullet drop, a simple application of gravity on to the bullet. This concept is also applied to tank shells, grenade launchers, and regular missiles. Also with long ranged projectiles, they have a form of traveling distance associated with them, it takes estimation to hit with them. Theoretically is can be managed easily, however this will be done with all the projectiles of 64 players, and all the destruction occurring.
With the large battlefields snipping can be challenging at times

Driving Vehicles 

When driving vehicles, there are physics involved with handling the vehicle. Some land vehicles will have a suspension based wheels, so you will bounce and land after flying throw the air. Helicopters seem to have a gyroscope system, where the vehicle will accelerate dependant on the rotation of the copter. Jets can perform crazy acrobatic moves such as loops, corkscrews and will stall if they fly too high.
The cock pit of airplanes can be confusing with all the angles along each tilt being displayed
Sometimes the physics allows for some silly vehicular mayhem. For example when you destroy a fast moving jeep/jet, its main body will still exist and retain the velocity which it was at. This is has resulted in the death of hundreds of players including me. A more hilarious approach is launching a light vehicle with explosives, with friends. This will require a lot of explosives, and correct vehicle positioning. If vehicle is too far from the pile of explosives, this will just push the vehicle forward. Done right and you will have a very nice view of the battlefield, for about 5 seconds.

Conclusion

            All the physics for Battlefield 3 combined with the amazing animation, graphics, and amount of content makes Battlefield 3 a great game. With this the frostbite engine 2.0 was a great iteration of the engine utilizing Havoc and other technology/techniques. In the end, Frostbite 2.0 was originally designed forthe “next generation” of consoles, although a Frostbite 3.0 is close to completion right now. With Battlefield 4 almost a month away, I'm honestly excited to see what the Frostbite 3.0 engine will do.