Last month I spent a a couple weeks creating a prototype with a good friend. We were aiming at creating a game in a month for the Dania Game Expo. The idea for the game was a stressful physics based multiplayer warehouse manager. The central mechanic is to manage the warehouse inventory by physically moving it around.

Unfortunately we abandoned the project due to personal issues. However in the little time we had I managed to create the first iteration of the player controller (Shown above). I implemented a physics controller and a graphical representation using Inverse kinematics. There were also a bunch of things that I didn't have time to figure out. Like how and where to place the arms when not lifting a box.

In this post I want to go over some of the techniques I used and my approach for creating physics based controllers for games.

Tip #1

Know your gameplay

We wanted the game to have a high focus on the player controller. Initially we looked to games like Fall Guys and Gang Beasts. However unlike those games we wanted the player to have a bit more control over the characters movements.

We wanted the main source of tension in the game to be in the management of inventory; Reciving, Sorting and Delivering boxes. The player shouldn't be fighting too hard doing simple movements. With that being said we wanted the environment to affect the player. Bumping into other players and narrow paths with wide goods can be fun and challenging.

So the first tip is that you should have your gameplay in mind. What should the player be able to interact with? What happens if something the player is holding hits a wall? How much control should the player have in the air? These are some of the questions you want to answer early in the development process. You should always have the player experience in mind when answering anything. What is your goals with the game design?

Gif of a IK rigged physics character picking up a box.

You might not have all the answers in the beginning. Making physics and player controllers in general requires many iterations. Play testing is essential to figure out if the controller works. Often you'll only find out when a prototype is already made and interacting with the environment. Don't be afraid to scrap everything and start over if the first approach doesn't work.

Depending on your gameplay, the physics code might look very different. Some games require a realistic physics simulation while others a fun approximation of real world physics.

Tip #2

Split the problem into individual forces

When your goal is realistic physics a good starting point is a physics engine. Often game engines have a physics engine built-in. If you're building your own engine there are many open source physics engines on github. Unity for example provides the Rigidbody Component, which automagically adds physics to any object.

But how do I make the object behave as to fit my gameplay? Often people struggle with turning the prebuilt building blocks into a proper physics controller. The key is when applying forces to a rigid body you have to think like an engineer. (My time studying mechanical engineering come in handy here.)

Most complex behavior is result of very simple forces acting upon a body. By splitting it into simple vectors you get powerful but indirect control as a gameplay programmer. In Unity you can do this with Rigidbody.AddForceAtPosition(Vector3 force, Vector3 position, ForceMode mode). Instead of controlling speed directly. You instead can control the amount of drag, friction and thrust. It becomes a balancing act where you have to tune a multi variable equation to get it just right to your needs.

A huge advantage is emergent behavior occurring from different forces. For example the relation between the center of mass and the center of lift in a helicopter is the factor that makes it lean forward. You get those kind of details for "free" with a good simulation.

So the second tip is to think like an engineer! A good place to start is to learn about statics which is the analysis of forces and torque on physical systems. Sometimes, however, you want more direct control of your gameplay and do not care about the realism of your physics.

Tip #3

Simplify and Cheat!

Not all built-in physics solutions will fit your needs. For many "arcady" games, you rarely get the desired result from simply slapping your engine's built-in Rigid body on your player. Many times you'll have to roll out your own physics.

Instead of running a true full physics simulation you can simplify and only change the relevant variables directly. By programming the physics yourself you will get a lot more direct control of the behavior of your controller. Often you can also get away with simplifying collision detection. Especially If you're not making a hyper competitive fighting game.

The player wont notice. I promise! Players only focus on the "feel"/ juice of your game. Like the other approach you should still iterate, but now you have much more direct control of the player experience. Find what you like and what fits to your game!

Do not expect any emergent behavior however, you'll have to fake it until you make it! A lot of times you can just cheat with a bunch of stuff. Take the helicopter example. Instead of relying on physics to make the body lean forward you can just rotate the graphics based on speed. Get stuck in corners or small steps? Make the player float!

The best example is 2D platformers. Over the years developers have mastered a bunch of techniques (cheats!) to make controllers feel better. Stuff like:

  • Customizing jumps with curves
  • Having extra time to jump even after you left the ground ie. coyote jumping

Game Maker's Toolkit have made a cool interactive tool to try these tricks out for yourself: Platformer Toolkit

Screenshot of Platformer toolkit

Another tip is to Separate graphics from physics. All this fakery requires a solid separation of the physics and graphics. That makes it a lot more straight forward.

In the end I ended up with a hybrid approach. By combining both I got the result I wanted. There's a lot of trickery, but it also built on a realistic physics simulation that respects mass etc.

That's all for this post folks. I hope you found some of the tips useful. I'll leave you with some more learning material if this topic interests you: