informa
/
2 MIN READ
Featured Blog

Understanding ForceMode in Unity3D

An aid to understanding how the four ForceModes in Unity3d differ.

While fiddling with the player handing for Chalo Chalo, it became important for me to get a better grasp on the differences between the four force modes in Unity3D.

If you have objects that use Unity's physics system, via a rigidbody component, you can add forces to them to get them to move. Forces can be added using one of four different 'modes'The names of these modes aren't very enlightening and I don't think the Unity3D documentation is very clear about their differences. For my own reference, and in case it helps others, this is what I've figured out.

  • ForceMode.Force. If the AddForce call occurs in a FixedUpdate loop, the full force supplied to the AddForce call will only have been exerted on the rigidbody after one second. Think of it as 'Force exerted per second'
  • ForceMode.Acceleration. Like ForceMode.Force, except the object's mass is ignored. The resulting movement will be as though the object has a mass of 1. The following lines will give the same result
    rigidbody.AddForce((Vector3.forward * 10),ForceMode.Force);
    rigidbody.AddForce((Vector3.forward * 10)/rigidbody.mass,ForceMode.Acceleration);
  • ForceMode.Impulse. The entirety of the force vector supplied to the AddForce call will be applied all at once, immediately.
  • ForceMode.VelocityChange. Like ForceMode.Impulse except the object's mass is ignored. So the following lines give the same result:
    rigidbody.AddForce((Vector3.forward * 10),ForceMode.Impulse);
    rigidbody.AddForce((Vector3.forward * 10)/rigidbody.mass,ForceMode.VelocityChange);

I made a little test to verify this. The script demonstrates how the ForceModes work by canceling out their differences through modifying the values passed to the AddForce call.
 

Here's the C# script that was attached to each of the cubes. In the inspector, the forceMode property of each was set to use one of the four modes.

using UnityEngine;
using System.Collections;

public class force_force : MonoBehaviour {

	public ForceMode forceMode;

	void FixedUpdate() {
		AddForce();
	}

	void AddForce(){
		float massModifier=1f;
		float timeModifier=1f;

		// Modify things to make all give same result as ForceMode.Force

		if (forceMode==ForceMode.VelocityChange || forceMode==ForceMode.Acceleration){
			massModifier=rigidbody.mass;
		}
		if (forceMode==ForceMode.Impulse || forceMode==ForceMode.VelocityChange){
			timeModifier=Time.fixedDeltaTime;
		}

		rigidbody.AddForce(((Vector3.forward * 10) * timeModifier)/massModifier,forceMode);
	}

}

Latest Jobs

Treyarch

Playa Vista, Los Angeles, CA, USA
9.12.23
Senior Level Designer (Zombies)

PlayStation Studios Creative Arts

Petaling Jaya, Selangor, Malaysia
9.14.23
Lead/ Senior Asset Artist

Treyarch

Playa Vista, Los Angeles, CA, USA
8.22.23
Senior Gameplay Systems Engineer - Treyarch

High Moon Studios

Carlsbad, CA, USA
9.18.23
VFX Artist
More Jobs   

CONNECT WITH US

Explore the
Advertise with
Follow us

Game Developer Job Board

Game Developer

@gamedevdotcom

Explore the

Game Developer Job Board

Browse open positions across the game industry or recruit new talent for your studio

Browse
Advertise with

Game Developer

Engage game professionals and drive sales using an array of Game Developer media solutions to meet your objectives.

Learn More
Follow us

@gamedevdotcom

Follow us @gamedevdotcom to stay up-to-date with the latest news & insider information about events & more