add force code example

Example 1: Rigidbody.addforce

using UnityEngine;public class ExampleClass : MonoBehaviour
{
    public float thrust = 1.0f;
    public Rigidbody rb;    void Start()
    {
        rb = GetComponent<Rigidbody>();
        rb.AddForce(0, 0, thrust, ForceMode.Impulse);
    }
}

Example 2: how to make rb.addforce 2d

public Rigidbody rb; //make reference in Unity Inspector

public float SpeedX = 0.1f;
public float SpeedY = 0.5f;

rb.AddForce(new Vector2(SpeedX, SpeedY));

Example 3: unity rigidbody addforce

rb = GetComponent<Rigidbody>();
rb.AddForce(new Vector3(1.5f,1.5f,1.5f));

Example 4: rb.addforce c#

rb.AddForce(0, 0, 5 * Time.deltaTime);

// Time.deltaTime is optional ( Make sure that "T" is caps)

Example 5: rb.addforce 3d c#

rb.AddForce(0, 0, 5 * time.deltaTime);

// time.deltaTime is optional