CodeBlanks Logo Icon CodeBlanks

Applying force with AddForce

Learn to apply force to an object with Rigidbody.AddForce.

Applying force with AddForce

To move physics-driven objects, Rigidbody.AddForce is used instead of directly modifying Transform position. This method applies a vector containing direction and magnitude to the object.

Rigidbody rb = GetComponent<Rigidbody>();
// Launch the object upwards
rb.AddForce(Vector3.up * 10f);

Objects propelled by AddForce react naturally with physics responses when colliding with other obstacles.

ForceMode varieties

ForceMode.Force is used for sustained thrust applied over time (like a rocket engine). ForceMode.Impulse is ideal for sudden hits and jumping effects.

// One-time jump impulse
rb.AddForce(Vector3.up * 5f, ForceMode.Impulse);

Continuous forces are usually called inside FixedUpdate, whereas instant impulses are fired just once in a single frame.

Practice Print applied force

Assign "Impulse" to forceMode and 10 to magnitude. Print Applied Force: 10 | Mode: Impulse to the console.

Starter code

Player.cs
using System;

class Program
{
    static void Main()
    {
        // forceMode ve magnitude değerlerini tanımlayıp yazdır
    }
}

Sample solution

Player.cs
using System;

class Program
{
    static void Main()
    {
        string forceMode = "Impulse";
        int magnitude = 10;
        Console.WriteLine("Applied Force: " + magnitude + " | Mode: " + forceMode);
    }
}

Expected output

Applied Force: 10 | Mode: Impulse

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which ForceMode type is appropriate for applying an instantaneous jump or explosion impulse?

  • ForceMode.Impulse Correct answer
  • ForceMode.Acceleration
  • ForceMode.VelocityChange
  • ForceMode.Continuous

Explanation: ForceMode.Impulse applies an instant force impulse in a single frame, factoring in the object's mass.

2 Specify Impulse force mode

Question
rb.AddForce(Vector3.forward * 10f, ForceMode.____);
Answer
rb.AddForce(Vector3.forward * 10f, ForceMode.Impulse);

Explanation: In Unity, Impulse is selected from the ForceMode enum to apply an instant hit force.

3 Force concepts

Term Meaning
AddForce Applies physical force to Rigidbody
ForceMode.Impulse Instant impulse, mass-dependent
ForceMode.Force Force applied continuously over time
Vector3.up Upward unit vector — (0,1,0)

All lessons in Beginner