Nobody can tell for sure who the inventor of guns was. However, they seem to have come about when the European armies began looking for ways to use Chinese powder. As a matter of fact, the history of hunting with rifles begins with turning military technology into practical peacetime uses.
The very first guns were in fact miniature cannons as they were made out of metal tubes that used gunpowder in order to force a ball-shaped lead projectile forward. They fired with fuses rather than triggers. You can also buy airsoft assault rifles at alchemyairsoft.com/collections/rifles.
The first attempts to make these guns more practical go way back into the 16th century during the English Civil War when they tried to make them more convenient for foot soldiers, which led to the development of the trigger and a series of firing devices, like the matchlock, the flintlock, and the Wheelock.
As you might have expected, these rudimentary guns had a lot of problems as far as accuracy is concerned, and in some cases (more often than you would think) the soldiers gave up and threw the firearm at the enemy.
Another development for which no single person takes credit is rifling – cutting grooves into the barrel in order to improve accuracy. The practice became popular during the American Revolutionary War and it became well established in the hunting environment.