Here's my problem : I have a platformer-like game with a custom shooting system. You move your crosshair around, shoot and reload with the mouse. With the red crosshair dot you control there are four orange lines that follow your crosshair.
The orange lines get more distant or closer to the red dot according to the weapon you are using to indicate your accuracy (If you played Counter-Strike, you should know what I mean by this). The lines get more distant if you shoot, and closer if you stop to aim. The red dot also kicks forth and back if the weapon has some recoil (almost all have).
I did that so that if you keep shooting your powerful assault rifle at a full automatic rate, the accuracy of your shots will go out of the window, meaning that trigger-happy fingers will NOT succeed.
The shots are supposed to land instantly somewhere between the four lines. This is where the problem comes : EVERYTHING I tried just sent the bullets in random places across the window. I need help there, it's making me crazy! That's almost... 6 hours trying to fix it. Other than that, everything is well at the game (well, still need to work on the enemies AI, but that's later).
Generate a number with its maximum being how wide the "Box" is - X co-ord
Same as above except how tall it is - Y co-ord
now, you need to find out how far the center of your target is from the left and top (X,Y), then Subract half of the width of the box from the X(Of the target, not the random one. Do this again with the Y (target). Then finally add in the random X,Y coords. This should make all the shots appear within the box.
Hope this helped.
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G