add force unity 3d code example
Example 1: unity how to add force
public Rigidbody rb;
if(Input.GetKey(KeyCode.W))
{
rb.AddForce(100, 0, 0);
}
Example 2: how to add a force to an object unity
private Rigidbody2D rb;
public Vector2 direction;
public float force;
void Start()
{
rb = GetComponent<Rigidbody2D>();
rb.AddForce(direction * force, ForceMode2D.Impulse);
//rb.AddForce(--pass in Vector--, --can pass in ForceMode--);
}