Effect Types

Each effect is a ScriptableObject you create from the Assets, Create menu (Physics, Effects for 3D and Physics, 2D Effects for 2D) and list on a Force Effect Field or Direction. The strength a field passes in means something different for each effect, so read the strength line first.

Most effects have two switches, EffectLinear for pushing and EffectTorque for turning. A body only gets the parts that are on in both the effect and its ForceEffectReceiver (useLinear, useAngular). GravityEffect has no torque part. Wind has linear and torque in 3D, and linear only in 2D.

EffectStrength meansBehaviour
AttractA force, in the chosen ForceModePulls toward a point source or along a directional source’s direction. With EffectTorque it turns the body to face the source.
RepulseA force, in the chosen ForceModePushes away from a point source or against a direction. With EffectTorque it turns the body to face away.
TractorA speed in metres per secondSteers the body to that speed toward the source, slowing as it arrives, so it holds a steady speed and does not overshoot.
GravityAn acceleration in metres per second squaredA gravity well. Pulls toward the source and cancels world gravity on the body while it is inside.
SuspendA rate in 1 per secondBrings the body to a stop, as if held in a thick medium. At 1, about two thirds of the speed is gone after a second.
WindA multiplier on the wind’s forceGusting, swirling wind that applies real drag to the body.

Attract and Repulse #

The simplest effects. Choose the mode (a Unity ForceMode, or ForceMode2D in 2D) and the strength is applied as a force in that mode along the direction toward (Attract) or away from (Repulse) the source. Use them for magnets, explosions and shockwaves.

SettingWhat it does
modeHow the force is applied (Force, Acceleration, Impulse or VelocityChange).
EffectLinearPush or pull the body.
EffectTorqueTurn the body to face the source (Attract) or away from it (Repulse). In 2D the body’s right side faces the source.

Tractor #

A tractor beam. The strength is a speed in metres per second, and the body is steered to that velocity toward the source instead of being pushed, so it does not overshoot. Near a point source the speed falls away inside arrivalDistance so the body slows to a stop at the source.

SettingDefaultWhat it does
EffectLinearoffDraw the body toward the source.
EffectTorqueoffTurn the body to face the source, blended by the strength up to 1.
maxAcceleration0The most acceleration in metres per second squared the beam may apply. Zero for no limit.
arrivalDistance1The distance from a point source inside which the body slows to a stop.

Gravity #

A gravity well. The strength is an acceleration in metres per second squared toward the source. While a body is in the field its own world gravity is cancelled by counter acceleration, nothing on the Rigidbody is changed, so it falls normally again the moment it leaves. Build planets, black holes or low-gravity zones by combining it with a field and a matching radius or constant curve.

SettingDefaultWhat it does
disableBodyGravityonCancel the world gravity on the body while it is in the field.

Suspend #

Holds a body as if in a thick medium. The strength is how fast motion dies away, in 1 per second, applied as an acceleration so it does not depend on the physics time step.

SettingDefaultWhat it does
EffectLinearoffSlow the movement of the body.
EffectTorqueoffSlow the rotation of the body.

Wind #

Wind blows away from a point field, or along a directional field. The force is the real drag of the wind on the body: 0.5 x air density x drag coefficient x area x relative speed squared, where the speed is the wind relative to the body, so a body carried along at the wind speed feels nothing. The area is the shadow of the body along the wind, taken from its PhysicsData, or fallbackCrossSection when the body has none. The torque comes from the same force acting at the body’s centre of volume rather than its centre of mass, so a body with a large sail area turns to catch the wind.

SettingDefaultWhat it does
EffectLinearoff (on in 2D)Push the body.
EffectTorqueoffApply the torque of the wind acting off the centre of mass. Needs a PhysicsData on the body. 3D only.
volumetricDensity1.239The density of the air in kg per cubic metre, around 1.2 at sea level.
dragCoefficient1Around 1 for a blunt object and 0.5 for a rounded one.
fallbackCrossSection1The cross section in square metres used for a body with no PhysicsData. In 2D this is crossSection, the width the wind meets in metres.
metersPerSecond8The steady wind speed at full strength.
frequency0.3How often the wind gusts, in cycles per second.
magnitude1.5How much the speed swings each way during a gust, in metres per second.
turbulence0.15How quickly the wind direction wanders, within 30 degrees either side. Zero for a constant direction, around 0.1 to 0.3 for a breeze, higher is gusty and erratic. 3D only.

WindEffect.Force(source, strength, subject, data) returns the force in newtons for a body, and is public so you can use the same calculation in your own code.

2D differences #

  • 2D effects derive from ForceEffect2D and act on Rigidbody2D. They are created from Assets, Create, Physics, 2D Effects.
  • ForceEffectDirection2D acts along its right (X) axis because forward has no 2D component.
  • WindEffect2D has no torque and no turbulence, and uses crossSection instead of a hull.
  • Attract2D and Repulse2D use ForceMode2D.
  • TorqueToReachDirection2D works in radians even though Rigidbody2D.angularVelocity is in degrees per second, see Physics Maths.

Rate This Article!