2. Forcibles

Version 1.1.5

(This documentation needs updated)

PuppetJump is a physics based VR framework. Forcibles make dealing with Rigidbodies, and the physics that move them, less complicated. Forcibles use the analogy of a Motor to make things like force and torque easier to understand and apply to your objects. In PuppetJump, Forcibles play a key role in translating the positional data, provided by the hand held controllers of the virtual reality device, into forces that can actively participate in the physics simulation of your application. The utility of the Foricble class can be useful for any Rigidbody object.

There are always multiple factors in play when dealing with physics. It can be complicated and you might ask: why use physics at all? Why not just move objects via the transform?

By moving objects with force and torque, movement becomes more dynamic and appears less deterministic. Physics allows for motion to be interrupted, and influenced, by other objects through collisions. Physics also provides the opportunity to define individualized movement behaviors using additional characteristics like mass, drag and physics materials.

We use physics because ultimately it makes things feel more real.

 

The following is a description of the parts of the Forcible class and how they are used to effect the physics on a Rigidbody.

Whenever you add the Forcible component to a game object a Rigidbody will be added automatically if one does not already exist. The Forcible component requires a Rigidbody because it uses physics.

Forcible with Rigidbody

Forcible with Rigidbody

Colors

The Inspector for the Forcible component is color coded like a traffic light.

  • Red items are used for deceleration and stopping.
    (Brake and Angular Brake)
  • Yellow items are used for making objects yield.
    (Max Speed and Max Angular Speed)
  • Green items are used for acceleration and to make your objects GO!
    (Motors and Power)

Brakes

The Brakes on a Forcible adjusts the amount of drag put on the Rigidbody to control deceleration in velocity. The Angular Brake adjusts the amount of angular drag to control deceleration in angular velocity.

  • At brake set to 0 means max velocity / max angular velocity is allowed.
  • A brake set to 1 mean zero velocity / angular velocity is allowed.

Brakes work with or without Motors on the Forcible.

The example code below would set both the velocity and the angular velocity of a Forcible’s Rigidbody to zero regardless of the amount of force on it.

GetComponent<Forcible>().brake = 1.0f;
GetComponent<Forcible>().angularBrake = 1.0f;

Max Speeds

In a physics simulation, speed is the amount of change each Fixed Update. By setting the Max Speed and Max Angular Speed values on a Forcible you are able limit how fast an object can move, or turn, regardless of the forces put on it. These settings work with or without Motors on the Forcible.

Unity base unit of measurement is the meter. Considering that, here are some values you might want to consider when setting speed limits:

  • 2.2 meters per second is about 5 miles per hour
  • 44 meters per second is about 100 miles per hour
  • 342 meters per second is about the speed of sound

Motors

To add forces to an object a Forcible must have at least one Motor. You create Motors by clicking the Add Motor button.

Forcible Motor

Forcible with one Motor added

Index

The index of the Motor in the Forcible’s list of motors is shown in the top left. The first Motor’s index is 0. You can access a Motor by index via code in two ways:

GetComponent<Forcible>().motors[0]
GetComponent<Forcible>().GetMotor(0)

If you’re going to reference a particular Motor often it would be best to cache the reference:

private Motor myMotor;
void Start()
{
   myMotor = GetComponent<Forcible>().motors[0];
}

Name

You can also give a Motor a unique name for easier identification. To access a Motor by name via code:

GetComponent<Forcible>().GetMotor("MyMotor")

Remove

Motor’s can be removed from the Forcible at anytime including runtime. To remove a Motor by index:

GetComponent<Forcible>().RemoveMotor(0);

or by name:

GetComponent<Forcible>().RemoveMotor("MyMotor");

Type

How a Motor effects a Forcible depends on it’s Type. There are currently eight different types of Motors to choose from:

  • Directional – use to apply force to a local direction
  • Rotational – use to apply torque to a local axis of rotation
  • Target – use to apply force and torque towards a target transform
  • Target Position – use to apply force towards a target transform
  • Target Rotation – use to apply torque towards a target transform
  • Align To World – use to apply torque towards a world axis
  • Target Array – use to apply force and torque towards multiple target transforms
  • Look At – use to apply torque to look at a target transform

Drive and Angular Drive

Depending on the Type of Motor, it will have a Drive and or Angular Drive settings. The Drive analogy is loosely based on horsepower while Angular Drive is torque. Drive and Angular Drive share a set of parameters:

  • Solver – The method of applying force
    • Math – A mathematical spring model that calculates the force
    • Unity – A Unity spring model that calculates force
  • Active – True if the Drive is in use
  • Frequency – The attempted amount of change each Fixed Update
  • Damping – Can be used for easing when the Type of Motor is a Target or Align To World
    • At 1 the system is critically damped. (Settles the best it can)
    • At > 1 the system is over damped. (Sluggish, lags behind)
    • At < 1 the system is under damped (It will oscillate as it tries to settle)
    • If continuous motion is desired, it’s recommend to set damping to 0.

Power

The Power of a Motor is like the gas pedal. It’s value ranges from -1.0 to 1.0 and is essentially a multiplier on the Frequency of the Drive systems. At 1.0 the full power of the Motor is in use, at -1.0 full reverse power is in use, and at 0, the Motor is adding no forces to the object. Here’s an example of how you could adjust the power of a Motor using the up and down arrow keys:

private Motor myMotor;
void Start()
{
   myMotor = GetComponent<Forcible>().motors[0];
}

void Update()
{
   if (Input.GetKey("up"))
   {
      if(myMotor.power < 1.0f)
      {
         myMotor.power += 0.1;
      }
   }

   if (Input.GetKey("down"))
   {
      if(myMotor.power > -1.0f)
      {
         myMotor.power -= 0.1;
      }
   }
}

A Forcible can have as many Motors as you want. They will all work together to combine forces on the object. One Forcible might have several Motors that each serve a different purpose.