how to apply a force to a rigidbody to the direction code example
Example 1: how to make something addforce in the direction of something in untiy
dir = target.transform.position - transform.position;
dir = dir.normalized;
rigidbody.AddForce(dir * force);
Example 2: 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);
}
}