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

Unity Fixed Update Purpose

September 25, 2020

Unity

Fixed Update


Title: GameDev Stream — What is FixedUpdate For?
By: Infallible Code
Youtube – Information
Description: Quick rundown of the main purpose of using fixed update in Unity.


Overview

This video quickly covers the main purpose of using FixedUpdate in Unity. As most Unity users know this is commonly used for containing physics calculations, but they better describe why that is here. They explain that FixedUpdate is much more consistent as it is inherently time based, whereas Update is tied directly to frame rate, which can vary drastically from computer to computer or user to user. This consistency however is what also makes FixedUpdate bad for uses such as user input because they could basically be entering inputs between the FixedUpdates and they will not be picked up at all, which is obviously extremely bad.

HFFWS Working with the Rope Script

October 23, 2019

Human Fall Flat Workshop

Rope Script

Identifying Key Components

The main components of controllilng the rope script when it comes to placing it and connecting it with objects, are the handles and the start/end bodies. The handles are transform positions that dictate key points on the rope. Two is the standard, as they determine a beginning and the end for the rope, but more can be used to direct the rope in multiple directions. The start and end bodies are rigid body references which determine objects that will be physically connected to the ends of the rope.

The discovery with how the handles work opens the possibility for more rope configurations other than flat ropes which fall over other objects. Being able to guide a rope around in interesting patterns could potentially allow for setups that are more similar to actual pulley setups, where a rope needs to go around a wheel object at least once.

The first prefab I worked with that used the Rope script had rigid body objects with Fixed Joints on them that seemed necessary at first. While working with another rope using prefab (the hook), I found that it did not use these Fixed Joints. This showed that these are actually not manditory for connecting rigid bodies to the rope. It is just the rigid body reference on the Rope script itself for the startBody and endBody. Further investigation may show what purpose the Fixed Joints served.

Thesis Puzzle Generation – Pulley Information and Variations

October 17, 2019

Thesis Puzzle Generation

Pulley Variants

Pulley Wikipedia Page

Info #1 – Link

By: Wikipedia


Pulley

General

The wikipedia definition of a pulley is:
“a wheel on an axle or shaft that is designed to support movement and change of direction of a taut cable or belt, or transfer of power between the shaft and cable or belt”
The pulleys we will be generating are generally simpler setups. They mostly consist of a rope with a physics object (rigid body) on each end. This is because of how the system is used to create the pulleys. Ropes cannot be intertwined between objects accurately, so they are just generated above their setup locations and allowed to fall into position. As a final note, the pulley can also be tied into demonstrating the wheel and axle simple machine as well.

Varieties

Hook on an end to latch onto other objects

This focuses on the pulley’s inherent nature of changing the direction of force. The hooks allow the player to attach one end to various objects to move them into place. It could also be as simple as lifting other objects.

Object to move can be used as a platform
Focus on rotation of wheel

This would use the weight/friction of rope to rotate/spin the wheel that it is on while rope is moved. I am not sure how well the HFFWS system works with this.

Build a Compound Pulley

Since system does not allow for setup of complex block and tackle style pulleys, setup the environment for the player to build their own. This gets around the inability of the system itself by letting the player set it up. This would require building the environment in such a way (such as veritcal moving platforms or stairs around) to let the player move the rope through a series of wheels to build this pulley.

Lift Heavy Object

One end attached of the rope is fixed to a very heavy or massive object. The other end is where work is done to try to lift the heavy object. Examples of this could be a large door or simply a heavy platform. The system focuses on maximizing the overall force output. This will mostly be done by focusing on the free end of the rope, but applying an aiding upward force to the heavy mass may also be factored in.

Thesis Puzzle Generation – Seesaw Information and Variations

October 16, 2019

Thesis Puzzle Generation

Seesaw Variants

Lever Wikipedia Page

Info #1 – Link

By: Wikipedia


Seesaw

General

It’s basically a lever, which has the following definition from wikipedia:
Lever: “a simple machine consisting of a beam or rigid rod pivoted at a fixed hinge, or fulcrum A lever is a rigid body capable of rotating on a point on itself”

There are 3 classes of levers:
Class 1:

  • Fulcrum in the middle
  • Effort is applied on one side of the fulcrum and the resistance (or load) on the other side
  • Examples: seesaw, crowbar or a pair of scissors
  • Mechanical Advantage may be greater than, less than, or equal to 1

Class 2:

  • Resistance (or load) in the middle
  • Effort is applied on one side of the resistance and the fulcrum is located on the other side
  • Examples: a wheelbarrow, a nutcracker, a bottle opener or the brake pedal of a car
  • Load arm is smaller than the effort arm
  • Mechanical Advantage > 1
  • Called: force multiplier lever

Class 3:

  • Effort in the middle
  • Resistance (or load) is on one side of the effort and the fulcrum is located on the other side
  • Examples: a pair of tweezers, a hammer, or the jaw
  • Effort arm is smaller than the load arm.
  • Mechanical Advantage < 1
  • Called: speed multiplier lever

I will first be focusing on alterations of lever class 1 (which seesaw generally falls under) but it is good to keep the other classes in mind as options for later development. The variation of levers (and in turn, seesaws) can be broken down into varying a few factors, which then lead to a few direct varied physics outcomes. I separate them below:

Varied positions of: effort, fulcrum, resistance/load
Lead to varied: force, velocity, final positions

Varieties

The following are just a few takes on overall variations of seesaw and lever setups to provide varied experiences with the same general simple machine.

  • Maximize force to move heavy object
  • Move object at varying velocities
  • Jam seesaw
Maximize force to move heavy object

This follows the same general lever setup each time, with the fulcrum near one end, the effort is applied at this end closest to the fulcrum, and the load is found away at the other end of the lever. The load and fulcrum have little flexibility in this setup, but the effort can be applied in a couple different ways. This can be moving a heavy mass over to it, or dropping a mass onto it from a height.

Move object at varying velocities

There is a velocity of the lever points dependent on the difference in mass at the ends of the lever, which can be used to create a few different effects. A very high velocity can lead to creating a projectile of sorts. Understanding the difference in weights and how they pertain to the overall velocity of the system could be used for timing challenges. Finally, understanding that getting similar forces on each end of the seesaw will provide a slow and steady motion could be used for challenges where the most time possible is needed from the movement of the lever (maybe the seesaw carrying something all the way up resets the seesaw by destroying the object).

Jam seesaw

This approach is just using the seesaw to lift one end, then placing an object in the gap so that further alterations to the seesaw do not allow it to return back down fully to its resting position. This will most likely be used to create ramps of some kind.

Tutorial – Creating a Realistic Boat in Unity

August 14, 2019

Realistic Boat Physics

Unity

Harbrador – Make a realistic boat in Unity with C#

By: eriknordeus

As someone interested in using real world physics and applying it with Unity’s physics engine, this tutorial just looked very interesting and promising. It appears they do a lot of work determining buoyancy as well as air and water resistance using the actual mesh of an object. They also split the code up in a nice way, separating a lot of the math into its own class to keep scripts organized and easier to use/read, so I wanted to look into that organizational setup. Overall, this is just a cool project that has a lot of factors I want to learn more about (physics in unity, organizing scripts, applying real world concepts to Unity/games).

Thesis Game Concept – Buoyancy

February 6, 2019

Buoyancy Game Concept

Thesis Physics Game Concept

This concept focuses on creating a physics-based game with a lot of variable parameters using buoyancy to guide the main mechanics.

The first focus is just setting up a script that handles adding buoyancy force to an object. This script was named BuoyancyApplicator. It has a section of variables dedicated to determining the buoyancy force (all the variables in the basic buoyancy force equation), a section dedicated to different geometry dimensions (to determine volume for the previous equation), and then other Unity specific variables (such as RigidBody component). The standard buoyancy force equation used is:

(buoyancy force) = ((liquid density) * (acceleration due to gravity) * (volume of displaced liquid))

All of these are variables we can alter to provide a different experience, but for the simplest version in a given scenario, we can keep gravity constant, the volume displaced will be a constant (from the shape of the object) as it will be fully submerged the entire game, and liquid density just changes when the object goes from one liquid to another.

The game will involve the player controlling an object going through different liquids, so we needed a way to account for this transition. Since we just need to change it upon entering a new liquid, I placed the update for the liquid density variable in the OnTriggerEnter, and just have the “liquids” has trigger collider areas.

In an attempt to make it more physically accurate, I implemented Unity’s own rigidbody drag factor. Fluid drag is a fairly complex calculation, so in an attempt to just mimic it simply, I set the drag equal to liquid density times an arbitrarily defined drag coefficient that is manually assigned. I am not entirely sure how Unity’s rigid body drag works, but this approach seemed to give the desired result for the most part. It was especially helpful for cases where I had the object speed up a lot going through a very dense liquid, and then slowing down when entering a less dense liquid. All of this together even worked to have the object sink when it entered a very low density liquid.

Compiling List of Physical Phenomena for Game Analysis

January 10, 2019

Physical Properties to Observe in Games for Thesis

List of Physical Properties/Phenomena/Measures

I am compiling a list of physical factors that could be considered as the system or parameters to control/set for my thesis project. This will help me determine what factors I should be looking for in the games I am analyzing, as well as helping me develop a concept for the game to showcase the thesis design.

What are physical properties that could be coded as systems in games? Look for equations for general physical properties:

  • Force: Wikipedia – Force
    • F = dp/dt = d(mv)/dt
    • If mass remains constant (which it generally does in most normal physical instances), this can be changed to the more well known F = ma (because dv/dt = a) [1]
    • F = ma
    • Gravity
    • Magnetism
    • Thrust – increases velocity of object
    • Torque – produces changes in rotational speed
    • Mechanical Stress – distribution of forces through extended body where each part applies force to adjacent parts
      • Causes no acceleration of body because forces within body balance each other
      • i.e. Polybridge games
    • Friction
    • Equilibrium
    • Continuum Mechanics
      • Pressure – distribution of many small forces applied over an area of a body
      • Stress(?) – usually causes deformation of solid materials or flow in fluids
      • Drag – decreases velocity of objects
    • Elastic Force
      • Elasticity
      • Hooke’s Law = F = kx
    • Four fundamental Forces of Natures:
      • Gravitation
      • Electromagnetic
      • Strong Nuclear
      • Weak Nuclear

Energy: Wikipedia – Energy

  • “In physics, energy is the quantitative property that must be transferred to an object in order to perform work on, or to heat, the object”
  • Work = Force * Distance
  • W= ∫_C▒〖F∙ds〗(Equation from Word is a bit messed up)
    • Work is equal to the line integral of the force along a path C
  • Potential energy – stored by an object’s position in a force field
    • Potential gravitational energy
    • Electrical
    • Magnetic
  • Kinetic Energy – for moving objects
  • Elastic Energy
  • Chemical energy – caused by fuel burning
  • Radiant Energy – carried by light
  • Thermal energy – due to object’s temperature

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.