1.
Introduction
2.
Moving RigidBody
3.
4.
Example
5.
5.1.
How does AddForce work in Unity?
5.2.
5.3.
How do you remove all forces from Rigidbody Unity?
5.4.
How do I reset my Rigidbody?
5.5.
What is the ForceMode.Impulse Method?
6.
Conclusion
Last Updated: Mar 27, 2024
Easy

# Moving RigidBody

Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

## Introduction

In this blog, we will learn about moving RigidBody in Unity using the AddForce method with its example. So, letâ€™s begin with the introduction.

Rigidbodies let your GameObjects interact with physics. The Rigidbody can accept forces and torque to move your items realistically. To be impacted by gravity, operate under extra forces via scripting, or interact with other objects using the NVIDIA PhysX physics engine, each GameObject must possess a Rigidbody.

Source: docs.unity3d.com

Rigidbodies must be explicitly added to GameObject before the physics engine may impact them. From the Components->Physics->Rigidbody menu, you may add a Rigidbody to your selected object. Your object is now physics-ready; it will fall under gravity and accept forces, but you may need to add a Collider to get it to behave precisely as you want.

We are done with the introduction to RigidBody. Letâ€™s learn about moving RigidBody now.

## Moving RigidBody

There are two methods of moving a gameObject in Unity:

1. By Changing Position Coordinates: By altering the location of a gameObject without concern for its physics or other similar components. So far, we've done this by simply adding a value to the object's X position per frame.
2. Rigidbody Physics: When dealing with physics-based objects, it makes more sense to apply forces or adjust their velocity rather than update their location directly. It appears more realistic.

In this blog, we'll understand the AddForce() method provided by the class Rigidbody.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

The Rigidbody's force is increased by using the RigidBody.AddForce() function. Force is applied constantly along the force vector's direction. Changing the ForceMode mode changes the kind of force to Acceleration, Impulse, or Velocity Change.

At the moment of the call, the results of the forces applied using this function are collected. The physics system applies the effects during the following simulation run (after FixedUpdate, or when the script explicitly calls the Physics.Simulate method).

Because this function has multiple modes, the physics system merely gathers the resulting velocity change rather than the force values passed. Assuming deltaTime (DT) equals the simulation step length (Time.fixedDeltaTime) and mass equal the mass of the Rigidbody to which the force is applied, the velocity change is computed as follows for all modes:

• ForceMode.Force: Interprets the input as force (measured in Newtons) and changes the velocity by the value of force * DT / mass. The effect depends on the simulation step length and the body's mass.
• ForceMode.Acceleration: parameter is interpreted as acceleration (measured in meters per second squared), and the velocity is changed by the magnitude of force * DT. The simulation step duration determines the effect but not by the body's mass.
• ForceMode.Impulse: The parameter is interpreted as an impulse (measured in Newtons per second), and the value of force/mass changes the velocity. The effect is affected by the body's mass but not by the simulation step duration.
• ForceMode.VelocityChange: The parameter is interpreted as a direct velocity change (measured in meters per second), and the force value changes the velocity. The impact is independent of body mass or simulation step length.

Only an active Rigidbody may be subjected to force.AddForce has no impact if a GameObject is inactive. Furthermore, the Rigidbody cannot be kinematic. When a force is applied, the Rigidbody's state is set to awake by default unless the force is Vector3.zero.

## Example

The following script will apply a continuous force to our object in the x-direction.

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ForceController: MonoBehaviour
{
Rigidbody rb;

void Start()
{
rb = GetComponent<Rigidbody>();
}

void FixedUpdate()
{
}
}``````

We've finished with the blog; let's move to faqs.

#### How does AddForce work in Unity?

Unity describes AddForce as "adding a force to the rigid body." This force is then applied to the GameObject. This is useful for projectile shooting, vehicle launch, pushing away things in an explosion, or moving characters.AddForce, in a nutshell, provides velocity to your GameObjects.

#### What is AddForce in Unity?

It gives the Rigidbody more force. Force is applied regularly along the force vector's direction. Only an active Rigidbody may be subjected to force.AddForce has no impact if a GameObject is inactive.

#### How do you remove all forces from Rigidbody Unity?

if you want to remove all forces, use rigidbody.velocity = Vector3. zero

#### How do I reset my Rigidbody?

You do that by resetting the velocity and the angular velocity to Vector3(0, 0, 0);.

#### What is the ForceMode.Impulse Method?

ForceMode.Impulse parameter is interpreted as an impulse (measured in Newtons per second), and the value of force/mass changes the velocity.