Mastering 2D Rigid Body Collision Resolution Explained

BYMark Howell 2 years ago5 MINS READ
Mastering 2D Rigid Body Collision Resolution Explained

Today in Edworking News we want to talk about 2D Rigid Body Collision Resolution.
From Mario bouncing off a Goomba to two cars bumping into each other in a racing game, dealing with collisions is such an integral part of most video games that we often take it for granted. In this series of blog posts, I want to show you what actually goes on behind the scenes in a physics simulation like the one above.
While we're going to look at this through the lens of video games, this post is really about the actual math and physics of collisions. Video games are just a nice way to contextualize these concepts and help make things a little less abstract.
While these articles will involve a fair bit of math, please don't be discouraged by that if you don't consider yourself to be a "math person". I think this kind of thinking is harmful and actively prevents you from engaging with topics that you might actually enjoy! Many times, it's the math notation that makes things look more complicated than they actually are because it's so information-dense and unfamiliar.

Copy link Rigid Bodies

The specific kind of physics simulation we are going to cover is called rigid body physics. A rigid body is a body that does not deform when subjected to forces. This is an idealized model because true rigid bodies do not exist in the real world; everything deforms on the molecular level even if this deformation is not visible to the naked eye. For most physics simulations, trying to simulate this level of detail is not only extremely difficult and computationally expensive, it's also unnecessary.

Copy link Collision Detection vs. Collision Resolution

In a video game engine, dealing with collisions can be broken down into two distinct phases: collision detection and collision resolution. Collision detection is about determining which bodies in our scene are colliding. This usually involves a bunch of geometry to check if two shapes are intersecting or overlapping. Collision resolution is the process of figuring out what needs to happen to two colliding bodies based on their current movement directions, speeds, materials, and other factors.

Copy link Defining the Problem

Most games run in a big loop. To move items on the screen, the game engine continually calculates positions of various objects. Velocity is a vector quantity, meaning it has both magnitude and direction. We can represent an object's current velocity with an arrow, where the length of the arrow represents the object's speed, and the direction the arrow points represents its travel direction.

Edworking
All your work in one place
All-in-one platform for your team and your work. Register now for Free.
Get Started Now

Copy link What is a Collision?

We learned that two bodies are said to be colliding if they are moving towards each other and their geometries overlap. However, understanding the exact mechanics of a collision involves both velocity and displacement calculations.

Copy link Surface Normals

The normal direction of a surface is always perpendicular to the surface. It is the direction that points directly away from the surface. Normal directions are represented with a normalized vector, a vector with length 1.

Copy link The Dot Product

To calculate how much of one vector is pointing in the same direction as another, we can use the dot product of the two vectors.
In English, the dot product of two vectors is the length of the scalar projection of one vector onto the other, multiplied by the length of the vector we’re projecting onto.
Using the concepts of dot products and surface normals, we can analyze the scenarios under which objects interact during collisions.

Copy link Conclusion

If you made it to this point, pat yourself on the back! We now have a formal definition of what a collision is, as well as the set of equations we are trying to solve when resolving collisions. In the next post, we'll dive deeper into the actual physics behind collisions.

Edworking is the best and smartest decision for SMEs and startups to be more productive. Edworking is a FREE superapp of productivity that includes all you need for work powered by AI in the same superapp, connecting Task Management, Docs, Chat, Videocall, and File Management. Save money today by not paying for Slack, Trello, Dropbox, Zoom, and Notion.

Edworking
All your work in one place
All-in-one platform for your team and your work. Register now for Free.
Get Started Now

Copy link Remember these 3 key ideas for your startup:

  1. Optimization is Key: Efficiently dealing with collisions in game engines involves breaking tasks into manageable sub-tasks, like collision detection and resolution, which can also be applied to other business processes. Understanding these processes can be essential for startup success.
  2. Simplify Complexity: Just as rigid body approximation simplifies real physical interactions, simplifying complex business processes without compromising realism can save computational and operational resources. Learn how to streamline your processes for better efficiency.
  3. Leverage Tools Efficiently: Mathematics and physics are essential for developing efficient gaming engines. Similarly, utilizing productivity tools like Edworking can make processes streamlined and more efficient.
  1. Caption: Physics simulations are simplified to make real-world calculations feasible.
    Feel free to discuss this article and reach out for more information!
    Twitter: @ksassnowski
    For more details, see the original source.
Mark Howell

About the Author: Mark Howell

LinkedIn

Mark Howell is a talented content writer for Edworking's blog, consistently producing high-quality articles on a daily basis. As a Sales Representative, he brings a unique perspective to his writing, providing valuable insights and actionable advice for readers in the education industry. With a keen eye for detail and a passion for sharing knowledge, Mark is an indispensable member of the Edworking team. His expertise in task management ensures that he is always on top of his assignments and meets strict deadlines. Furthermore, Mark's skills in project management enable him to collaborate effectively with colleagues, contributing to the team's overall success and growth. As a reliable and diligent professional, Mark Howell continues to elevate Edworking's blog and brand with his well-researched and engaging content.

Startups

Try Edworking Background

A new way to work from anywhere, for everyone for Free!

Get Started Now