I found this, it is 4.11 and i forgot what title on big comment really means. Some though shortcut, but i forgot it.
This is optimized version that uses unreal functions, i have somewhere older version made out of camera location and mouse screen location and much more trigonometry than this.
This assumes floor level at 0,0,0, if different level above 0 you add second offset to pelvis offset
I remember how it is calculated:
You have world location and forward vector for camera looking at mouse pointer. This is vector and location for where pointer is in 3d relative to camera.
From world location you can get length of one side of triangle (it is height of camera above horizontal plane)
Also cosinus alpha is cosinus of angle beetwen vertical vector and vector your camera is looking at mouse pointer.
So simple trig gives you distance you looking for: Height/cos(alpha).
Now you have camera forward vector and its length, you can multiply that, add to world location of camera, and you get where on ground plane mouse pointer really is.
It is hard to remove any offset between where you are aiming and where mouse pointer is, because your character usually shoots from hip (or shoulder) height, and this adds visible offset. However this calculation shoots at point exactly above mouse, if you shot from pelvis it will shoot at 90 units above ground.
For extra precise aiming you need use animation blueprint, find there exact direction weapon needs to shoot at target, then use aim offset to rotate weapon correctly, and shoot along forward vector of weapon.
You need both calculations. Mine to find where on floor plane is mouse (for walking), and accurate 3d line trace, when you aim at enemy.
But for top down games do not overdo with accuracy etc. Spending 3 months to get perfect foot placement and weapon aim direction is not worth it for games like that.