Apply impulse force to an object in Unity 3D

Hello programmers, In this article, I will show how to apply impulse force to an object in Unity 3D. We will use the AddForce()method to perform this task.

Applying Force to the game object makes the experience of the game even better. Let’s get started with the building process.

AddForce()

Using the AddForce() method, one may move a physical item or alter its speed or direction of motion.

However, fixed update may also utilise add force to apply a constant force.

One argument is mandatory and one parameter is optional for the function.

The first parameter is a vector that denotes the direction and magnitude of the applied force.

Syntax:

Rigidbody.AddForce(Direction, ForceMode);

Impulse

The manner of force being applied is the second parameter. If this is omitted, the type “Force” will be used by default.

A Rigidbody that is impacted by mass suddenly changes is referred to as experiencing a “impulse”

This mode is excellent for imparting sudden forces, as those from collisions or explosions.

Syntax:

Rigidbody.AddForce(Direction, ForceMode.Impulse);

C# script:

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

public class Add_Force : MonoBehaviour
{
    Rigidbody rig;

    float magnitude = 5;

    // Start is called before the first frame update
    void Start()
    {
        rig = GetComponent<Rigidbody>();
        rig.AddForce(Vector3.forward * magnitude, ForceMode.Impulse);
    }

}

Leave a Reply

Your email address will not be published. Required fields are marked *