How to add force towards where the camera is pointing?

I’m trying to make a weapon fire but when I’m firing, it is shooting towards a certain point in the map, and if I move at an angle (holding W and A at the same time) it shoots towards the direction I’m walking.

I just need a thing to insert here to make it go towards where the camera (player) is pointed

bullet.rigidbody.AddForce (<THINGY HERE> * 20);

Also I’m using js to do this.

If you use the transform of the camera instead of the bullet’s transform for applying force it should work. A script like this should work.

public GameObject Camera;
public GameObject Bullet;

OnMouseDown(){
Bullet.rigidbody.AddForce(Camera.Transform.Forward * 10);
}

Then you simply use the inspector to reference the bullet object and camera object. Hope this was helpful.

Try Camera.main.transform.forward