Shoot Projectiles at Mouse Pointer in a 3d space

Is there a way to make a line trace from camera to mouse cursor and the weapon that i’ve created to fire there if hits something, if not to fire at the max range?