In our engine, we are going to use a physics library called nVidia Physx. This library is very popular inside the video games industry and it will allow us to implement collisions and physics systems in our video game. We are going to implement static rigid elements for all the static geometry inside our scenario, then the Character controls to control our character and bots and, finally, lightning strikes on our scenario's elements. This is a very complete physics library which also allows us to add clothing or elements such as joints. So, we are going to see a small video on the different features the library has. <<PhysX FleX is a particle-based simulation technique for real-time visual effects. So far, we've showed examples for rigid body stacking, particle piles, soft bodies and fluids. In this video we'll be showing some of the new advancements within PhysX FleX. This scene shows two way coupling of cereal, represented by rigid bodies with particle-based fluid simulation. The milk is represented by up to 100,000 particles. Surface tension and viscous forces are modeled, and because the cereal pieces have a lower density than milk, they naturally rise to the surface due to buoyancy. The milk surface is rendered in real time using ellipsoid splatting and a sub-surface scattering approximation. In this smoke simulation the underlying fluid is modeled by thousands of particles tracking velocity and vorticity. Using particles provides a sparse representation of the air flow and allows smoke to interact with the other particle based objects. Because this is a grid free method, there are no fixed boundaries on the fluid flow. For rendering we advect hundreds of thousands of smoke particles through the underlying velocity field and render them with shadowing and a single scattering shader. Here are more examples of how FleX could be used. The stand-alone PhysX FleX library is available for early-adopters. Please contact us for more information.>> You can find more info on the library inside Nvidia's official page: nvidia.es/objects/nvidia-physx-es.html Here you can find all the information and even download the library, or the sdk inside the developers zone. This part is already on our video game's production. Now I will tell you how we've implemented this. But, what does a physics library do? How does a physics library work? To do so we are going to see a bit of a new video game such as BATMAN: ARKHAM KNIGHT, to let us understand how the video game actually works. With this video I want you to see the visual range and details video games have. We have spectacular graphics, totally cinematographic. This is the result the player will be able to enjoy. But, in the next video we will see what the player is actually playing with. Here we have a physics system on a scene in which we can see how the player interacts through a CharacterController. CharacterController is the same we previously saw in the Batman game. A capsule representing the character. This is how the game is working internally. Here we can see the different properties such as slope limit or step limit. The height, the jumps height. Different kinds of jumps, either just like Mario's video games, or with more or less handling qualities. The crawling, which is basically whether the character can move. As you can see, the physics system is really simple, it has no details, not like a video game. So our physics engine will allow us to implement what you have on the screen and that's what we will do next. To do so, we have created a PhysicsManager class which contains all the physics we need. Now, if we go back to the code, we have many member variables in the PhysicsManager class. We use the Physx class to create, which contains Media Physx library. In line 13 we have those physics groups we are going to use. In this case we are going to use three scene groups, PLAYER and BOT, which we will use as masks when we want to look at collision systems, so that we can depreciate some elements in our game to see if it collides with our scene, with a BOT or with a PLAYER. So we've got PhysicsManager builder and debuilder in lines 35 and 36, the Init method, which will initialize our physics, the destroy, which will take care of deleting all the physics part and the method CreateTriangleMesh, in line 40, which will generate a static geometry through a triangles mesh in Physx, the Update method which will allow us to update the physics engine. The TestCollisionPlayerVsItems method, which will check whether the player collides with and object and if he has to pick it. The CreateCharacterController method will create a character controller, as we have seen in the last video, and the two TestReycast methods, in lines 44 and 45, which will check if a lightning strikes something on physics. In the code, we have the builder which initializes the member variables again, and the destroyer, which destroys all the physics part. The initialization part takes care of initializing the physics library. The initializing physics system is standard. So here there isn't anything, we don't have any new code lines. The physics tutorial tell you how to do this, but it's basically the following code. Then we have the Visual Debugger part. Visual Debugger is an nVidia tool which allows us to see what is happening in the physics engine or what this physics engine is really working with that is, seeing it as we were seeing it in the beginning. We were seeing Batman's game, but actually the game physics isn't the same as the physics, which is what we are seeing at a visual level. So, this Visual Debugger helps us to see what the game engine is working with. It creates a Cooking Mesh, line 69, which will allow us to create static elements based on vertex structures and indexes. It creates the collisions group, the scene and the controllers managers. Lines 95 and 97. Next we have the destroy method, which is responsible of deleting everything in the memory and destroying the physics part. Next we have the CreateTriangleMesh method. This method receives the vertexes array with information on our scenario's geometry or on the mall we want to create in the physical model. The array, the indexes, the number of indexes, the number of sides, it would be similar to what we did in the RenderableVertex and the VertexStride. VertexStride is the number of bytes we have to skip in the vertexes array, to skip from a vertex to another one. Based on this info, it creates a Triangle Mesh Description which, with this Triangle Mesh Description can create a triangles mesh and it creates the RigidStatic model from this triangles mesh and it adds it as a scene actor. Again, the code isn't created by the wheel, it's simply a code which comes with the EPhysics documents, and we do it with the standard steps. Then we have the Update class, which updates our physics engine, simulating the scene, telling the simulated scene Simulate Elapsed Time and spreads the results to the scene. The next method we find is the Create Character Controller, which is the method which will allow us to create the capsule we saw on the second video. The Create Character Controller receives the position where the capsule or pill needs to be created, its height, its ratio, its Step Offset, which is the maximum height of the step which the capsule can go, the Slope Limit In Radians which is the maximum angle it can walk on the capsule without skidding and the physics group where the Character Controller we are creating belongs. Then, again it creates in Capsule Controller Description, it creates the controller and adds the group to all the created object's series and it gives it back. The next method we have is the Test Collision Player Vs Items, which tests the items' collision with the player. To do so, the only thing it does is going through all the items in our game which we will see later, and calculating the distance between the item and the player's position. If this distance is less than two, in this case, two meters, it tells the item chosen, the item manager which chose this item and tells the player he has chosen that item. To finish, we have the Test Ray Cast overloaded methods. The first method, in line 201, receives the origin and the destination point, the group of the mascara we want to use and an exit parameter which is the Out Position and another one is its exit parameter which would be the User Data. User Data will tell us which object we have collided with. This first method uses the second method we will see next, which is the second method, the difference apart from the origin is that instead of getting the destination, it receives the direction and the distance. So to call the second method, we calculate the direction between the origin and the destination and we calculate the distance between the destiny and the origin itself. So we call the second method, which is called Test Ray Cast, in line 210, and it creates an X Ray Cast Hit variable, in the line 21, which will give us back the Ray Cast exit information, to do so we use the Ray Cast Single method which receives the origin, the direction, the distance, the exit parameters, the Hit Info and the request filter, this way, in case it collides with something it will fill the Hit Info information, telling us the distance and the actor it collided with, in this case, Ray Cast, so if we go back to the ASEObject class, the part we left at the beginning, which was the collision part, when the Renderable Vertex part was created, we see that in case we have to create the geometry's collision mesh, it calls the method Create Triangle Mesh giving it the Vertex Buffers array, the indexes array, the number of vertexes and the number of indexes and the Stride between matrices, that is, from lines 234 to 244.