Unity – Exploring the Physics – Rigidbody and Drag

March 10, 2021

Rigid Body Physics

Unity



Title: How is Drag Calculated by Unity Engine?




Unity Forum – Link



Description:
Explanation of someone’s testing of Unity’s rigid body drag value.


Overview

I was just exploring Unity’s physics through Rigidbodys and Physics Materials to see what different feels and effects I could get with them, and decided to delve a bit further into them.

Rigid Body

I was just doing very general testing without much research this time around just to see what I got from using the different values. Mass acts pretty much how you would expect, as it requires more force to accelerate the object and stops it faster when friction is involved.

Drag

Drag and Angular Drag however were a bit trickier. While Drag did reduce the acceleration of the object as it moved, and eventually the velocity as force stopped being applied, it did not appear to matter what direction or shape the object’s facing direction created. I tested it with a narrow box, and moving straight on the narrow side and moving completely perpendicular with the long face of the box resulted in the same max speed values.

While I assumed this meant the shape did not matter whatsoever, I tested a capsule and a box with the exact same settings in the Rigidbody component on the exact same surface with the same physics material, and the box gave a lower terminal velocity than the capsule. I could not find any reason for this, other than possibly different collider types may have different effects on how drag or friction impacts them.

The link I attached above is a bit old now, but it comes from someone that belives they found an accurate approximation of Unity’s drag. At the very least, several sources I came across indicated that drag is linearly related to velocity in Unity’s Phys X engine, which is different from true drag which related to the square of the velocity of an object. I would have to do more testing to see if this person’s formula is accurate now (since this is about 5/6 years old now), and will have to do some more research to see if I can find any more up to date takes on Unity’s drag.

Physics Materials

I have not delved into these far yet, but the basics seem to make sense. I have only been exploring the friction values, and they seem to act as expected. The dynamic friction slows down objects rubbing against a surface as they move, and the static friction presents a force that needs to be overcome before the objects starts to move. Bounciness and the combining of the factors are aspects I have not yet tested at all currently.


Fig. 1: Quick Snap Shot of My Unity Physics Testing Table

Summary

With my quick initial tests, some interesting results have already come up. As noted previously, the primitives seem to be effected by physics differently somewhere in the pipeline. I suspect it is the drag factor, but it could also be friction, or some other inherent factor. Another interesting note is that both boxes had the exact same max speeds, even though one made much more contact with the ground. I would like to perform some more testing to see if the friction values at least make it accelerate slower overall, and reach max speed slower.

via Blogger http://stevelilleyschool.blogspot.com/2021/03/unity-exploring-physics-rigidbody-and.html

Video Game Physics – Constrained Rigid Body Simulation by Nilson Souto

January 5, 2019

Video Game Physics – Constrained Rigid Body Simulation by Nilson Souto

Toptal – Video Game Physics Tutorial – Part III: Constrained Rigid Body Simulation

By: Nilson Souto

Link to Erin Catto’s box2d.org

This appears to be a good follow up to the game physics GDC talk by Erin Catto I watched earlier. This serves as another listing of physics constraints and how they can apply in games, specifically when dealing with rigid body elements. I also learned the constraint type is “revolute”, not “resolute”. This article actually references Erin Catto and his Box2D site since it goes into his creation of the sequential impulse method.

Physics for Game Programmers: Understanding Constraints

January 5, 2019

Physics for Game Programmers: Understanding Constraints

Constraints in Game Physics

Youtube – GDC – Physics for Game Programmers: Understanding Constraints

By: Erin Catto

EDIT: Updated to correct “resolute” constraint to “revolute” (Jan 5, 2019)

Erin goes over the importance of physics constraints in physics game programming and how to implement them to add diversity and creativity when designing physics for games.

Erin explains that physics constraints are to physics programmers as shaders are to graphics programming. You can use the already existing recipes that will get the job done, but designing your own will allow you more flexibility and creativity.

Shaders – lighting, shadows; Physics constraints – revolute, prismatic

Position constraint: in example, it is a particle that is restricted to a surface. Appears the equation should be 0 if particle is on surface, than < 0 or > 0 depending on what side of the surface it is on if it moves away from surface.

Contact constraint: the contact points on the contacting bodies do not move relative to each other along the contact normal

Global solvers vs Local solvers: Global solvers would solve everything somewhat simultaneously by having everything in a single large matrix equation setup. Local solvers are used to do computations linearly and solve one thing at a time.

Physics solver will need to iterate multiple times to solve impulses, but cannot run enough times to get everything completely accurate which leads to some overlap.

Iterations allow for convergence of the system’s solution and the actual determined solution. The iterations and time for this convergence to occur vary based on the complexity of the physical system. In the examples, circle stacks with assigned mass values were used. It turns out heavier masses on top of smaller masses leads to much slower convergence, and it gets slower as the mass ratio increases. This occurs because the solver needs to bring the top circle to rest, but each iteration it does on the contact occurring between the two circles only removes a small amount of the large circle’s velocity because it does it relative to the size of the lower circle.

Warm Starting – since a lot of things in games aren’t moving all the time, you can “save” impulses to try initially later so that it will have a saved solution if it hasn’t moved and if it starts moving, it may be closer to the next solution already This does not do well with quick load changes.

Inequality constraints – only want impulses to be able to push, not pull (lamba > 0); For accumulated impulses, you actually don’t want each incremental impulse to be restricted by > 0, you just want to apply that to entire accumulated impulse. Sometimes you need negative incremental impulses to solve cases of overshooting. This is when impulse applied at a step is actually too great and you need to bring it back down.

Global solvers are great but too expensive.

Don’t use acceleration constraints because it leads to cases where you need an infinite force to truly stop an object instantaneously, which is theoretically what should occur in rigid body collision.

Link to Erin Catto’s box2d.org

References from the talk:
  • David Baraff: Coping with Friction for Non-penetrating Rigid Body Simulation
  • Metthias Muller: Position Based Dynamics

DIGM 540 – Engineering Statics Game Project – Forces in Unity

May 23rd, 2018

Forces in Unity

AddForce – Unity Official Tutorials

Youtube – AddForce – Unity Official Tutorials

The bare basics of scripting forces in Unity with rigidBody’s. The AddForce can take two inputs: a vector for direction and magnitude, and what type of force it is.

ForceModes
  • Acceleration – Continuous change; not affected by mass
  • Force – (Default) Continuous change; affected by mass
  • Impulse – Instant change; affected by mass
  • VelocityChange – Instant change; not affected by mass

AddTorque – Unity Official Tutorials

Youtube – AddTorque – Unity Official Tutorials

The bare basics of scripting torques in Unity with rigidBody’s. The AddTorque can take two inputs: a vector axis to apply torque around, and what type of torque it is. This is very similar to AddForce. Important to remember, Unity uses “LEFT HAND RULE” for rotation.

ForceModes
  • Acceleration – Continuous change; not affected by mass
  • Force – (Default) Continuous change; affected by mass
  • Impulse – Instant change; affected by mass
  • VelocityChange – Instant change; not affected by mass

Game Ideation

Engineering Teaching & Research Equipment – Armfield

EF-1.1 – Statics – Forces experiment kitYoutube – EF series video Statics Forces 1 1 3

The links are similar videos, the first is just directly to the site of those that made the kit, and the second is a Youtube link. This kit provides hand on experience for understanding a lot of topics based around static equilibrium. Topics such as 2D shape center of masses, force vectors, and much more can be covered with this tool.

Game Idea – Engineering Statics Game

Following the general idea of the kit shown above, the game environment is populated with nodes that apply controllable forces to a central ring object. These forces can be altered to change the position of the ring. The environment will spawn collectibles that the player must direct the ring towards in order to collect them. To move the ring, they will need to intelligently alter the forces applied by the nodes.

Quick sketch of concept
April 21st, 2018

Exploring Uses of Physics in Gameplay

Physics in Games: A New Gameplay Frontier – from Gamasutra.com

Article by Pascal Luban on Dec. 4th, 2007. This is an older paper explaining some of the possibilities opened up by computers becoming stronger and being able to process physics in games more readily. The author suggests ways of using physics as a core gameplay element as opposed to just some aesthetic element.

Feb. 19th, 2018

Research – Learning Physics Modeling with PhysX – Book

This is a book by Krishna Kumar going over the basics of PhysX as a physics engine. Could be useful for better understanding the default physics engine, PhysX, to properly drive engineering mechanisms.

Research – Book – Engineering Finite Element Analysis

“Finite element analysis is a basic foundational topic that all engineering majors need to understand in order for them to be productive engineering analysts for a variety of industries. This book provides an introductory treatment of finite element analysis with an overview of the various fundamental concepts and applications. It introduces the basic concepts of the finite element method and examples of analysis using systematic methodologies based on ANSYS software.”

This could be useful for learning and using finite element analysis, if looking into real time finite element analysis for use in games.

List of Physics Engines

Wikipedia page for Physics Engines

Real-Time
  • PhysX
  • Bullet
  • Havok
  • Vortex
High Precision
  • VisSim
  • Working Model