unity rb .add force towards vector 3 code example
Example 1: unity how to add force
public Rigidbody rb;
if(Input.GetKey(KeyCode.W))
{
rb.AddForce(100, 0, 0);
}
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);
}
}