Skärmbild 2022-04-18 163433.png

Nvidia PhysX

As part of my education at The Game Assembly, my project group and I were allowed to create a game in the first-person shooter genre. This was a great chance to experience and learn about what it takes to make something under these circumstances. However, the engine we had developed did not as of yet have any way to handle collisions or physics. This is where we decided to introduce Physx into the project. 

What is PhysX?

PhysX is an open-source software development kit made by Nvidia. It includes hundreds of tools for developers to use in facilitating high-quality physics simulations in games. These tools include but are not limited to, rigid- and soft-body simulations, Queries like raycasts and overlap checks. Most importantly for this project however were the real-time collisions.

Getting Started

Before this project, I had only minimal experience with PhysX, having only used it for the previously mentioned Queries. For this project, however, we needed a way for not only the player but also eventual AI agents to move around without falling through the floor or phasing through walls, this meant I needed to implement both collision detection and a way to simulate things like gravity and movement. And so I started with the basics. 

Setting the Scene

Like many developers trying something new, I began with the fundamentals. To aid me in this I used the PhysX Visual Debugger, another tool that allowed me to view the simulations as they happened in real-time without the overhead of hooking it into our established rendering pipeline. I started by making a handler to keep track of everything PhysX-related and then creating an empty Scene and defining some settings.

Cubes and Planes

The scene was now ready for some primitive shapes. To begin with, I created a plane, an infinitely thin rectangle to act as ground, on top of this plane I created a "few" cubes to test the collision, finally, I called the "Simulate" function from my PhysXHandler and watched the results in the visual debugger.

Where are we now?

With the scene set up and the physics loop running properly it was time to turn this testing into an actual game. I began by making a player controller using a PxCharacterController and writing some basic movement code for it. To make the game world I used vertex data exported from our map editor of choice to construct some PxTriangleMeshes. This all meant that we now had a player character who could walk around and would collide with all the walls, floors and roofs in the world we had created while being affected by forces like gravity in a believable fasion. 

Now what?

In addition to the basic collision and physics simulation, I also set up a more advanced query system for this project. In the future, I would like to experiment further with things like attaching collision boxes to animation bones to facilitate critical hit zones and ragdolls or perhaps dig deeper into dynamic colliders in order to build games with a larger focus on physics simulations. For this project, however, this was enough.