How can i shoot at the center of my crosshair? C++

The point of the approaches suggested in my first comment is to work in 3 dimensions instead of resorting to approximate trigonometry. Whether you use deprojection from the HUD into the world or a trace in the camera direction is immaterial. You need 3 things:

  • The world location where you want the shot to go based on your camera view direction
  • The muzzle location
  • The vector that “completes” this triangle (Viewpoint, Muzzle, HitLocation) in 3 dimensions (regardless of the orientation of this triangle) is your projectile direction, which you must obviously normalize and you then apply your bullet speed to that to get the required velocity of your projectile to reach that point.