I posted this on Mombot originally... I'm bored atm so I figured I might as well post it here too...

Well I had plans of making a decent aimbot for CoD2 but now that CoD4 is out I am focusing on it instead. This is just a little tut/explanation of the different value and calculations needed to do the aim properly. Something like this would've helped me alot when I started working on it so I figured I might as well post it and help others out....

The three main values you need to have and understand are:

1. lerporigin - vec3_t containing the position coordinates of the target

2. vieworg - vec3_t containing the position coordinates of you

3. refdefviewangles - vec3_t containing the displacement angle between your line of sight and the origin

For headshots only you need to do the following transformation of lerporigin.

**Code:**float newlerp[3]={lerpOrigin[0] , lerpOrigin[1], lerpOrigin[2]+60.0f};

By adding 60 the 3rd value, the z-value, it moved the position of the lerporigin into the middle of the target's head. This will come in handy later when we do our PITCH calculations.

Now that we have the new lerporigin where we want it, it's time to begin calculation the two angles for our aim. The angles are YAW (side to side) and PITCH (up and down).

First figure out the YAW...

**Code:** //********** YAW CALCULATIONS **********//

VectorSubtract(lerpOrigin,vieworg,vec);

distance=VectorLength(vec);

VectorAngles(vec,rot);

rot[1]=AngleNormalize180(rot[1]-refdefViewAngles[1]);

rot[0]=AngleNormalize180(rot[0]-refdefViewAngles[0]);

rot[2]=AngleNormalize180(rot[2]-refdefViewAngles[2]);

This block creates two new variables: vec & rot. "Vec" stores the differences in the (x,y,z) values of you and your target. "Rot" stores the angles between you and your target. To get the net angle between our line of sight and the enemy we subtract our refdefViewAngles from our rot angles. Since the maximum angle we want to aim left or right is 180 degrees we run our net angle through the AngleNormalize180 function.

From the "vec" variable we can extract vec[0] and vec[1] and assign them to a new variable called "screen".

**Code:** screen[0]=-vec[1];

screen[1]=-vec[0];

float screen0=screen[0]-160.000f;

float screen1=screen[1]-1280.000f;

When I was testing I had "screen0" and "screen1" printed to the screen so I could see how they were changing in realtime as I moved around the target. I noticed that my coordinates seemed to be centered on a random point that was offset by (160,1280) on the coordinate system so I subtracted those values from "screen" to produce the values I wanted. Below are 4 screenshots of me testing in-game... they're there to help you picture exactly what the "screen0" and "screen1" values represent.

http://img204.imageshack.us/img204/397/shot0105pi8.jpghttp://img529.imageshack.us/img529/2481/shot0106qj8.jpghttp://img529.imageshack.us/img529/9110/shot0107qs2.jpghttp://img46.imageshack.us/img46/1912/shot0108qk8.jpgUse the radar and the yellow box in the top left corner of each screenshot to familiarize yourself with the "screen" variable and to figure out exactly what it represents. If there is a negative sign where you don't think there should be one don't worry, they will be taken care of later on.

The next calculations are just simple trigonometry calculations to find the angle you need to aim at.

**Code:** float delta_deg=57.29577951;

float hyp=sqrt((screen0*screen0)+(screen1*screen1));

float angle_x=-(asin(screen0/hyp))*delta_deg;

if(screen0>0 && screen1>0) // quadrant D

angle_x=-180.000f-angle_x;

else if(screen0<0 && screen1>0) // quadrant C

angle_x=180.000f-angle_x;

else if(screen0<0 && screen1<0) // quadrant B

angle_x=angle_x;

else if(screen0>0 && screen1<0) // quadrant A

angle_x=angle_x;

When inputting the angles for your aim they must be in degrees but when using trig functions in C++ they are calculated in radians. The variable "delta_deg" is used here as the conversion factor between radians and degrees. The exact value of the conversion factor is (180/PI)... here it has been solved and rounded off. By using the values of "screen" with the Pythagorean Theorem we get the magnitude of the direct line between you and your target. Based on where the target is located on the coordinate system we adjust the angles to aim at the correct quadrant. When looking at the radar the quadrants are labeled counter-clockwise starting with "A" and the top right.

And FINALLY... the YAW calculations are done. We are left with a variable, "angle_x", that is the angle we want to send the game.

Now for the PITCH calculations... (don't worry, this is much shorter)

**Code:** //********** PITCH CALCULATIONS **********//

VectorSubtract(newlerp,vieworg,vec);

hyp2=sqrt((vec[0]*vec[0])+(vec[1]*vec[1])+(vec[2]*vec[2]));

angle2=(asin(vec[2]/hyp2))*(180/3.14159);

if(refdefViewAngles[0]>90.0f)

{

refdefViewAngles[0]=(refdefViewAngles[0])-360.0f;

}

Again we start off by getting the difference vector between us and our target. Here is where the "newlerp" variable we created in the beginning comes into play. We run through the same basic trig calculations as we did above to get the angle between you and your target. Another weird thing I noticed while testing (again by printing values to the screen) is how the "refdefViewAngles[0]" value changes as you look up and down. I assumed that when I looked down the values go from 0 to -85 (only 85 b/c of the 5 degree blind spot above and below you) and when I looked up the values would go from 0 to +85. However, when you look up, the values go from 360 to 275. Below are 2 diagrams I created to try to explain this better. The red line simulates the "centerview" mark.

The first image is what the normal game setup is. The second image is the new setup we created to make things easier. It helps keep things more uniform and less confusing.

After we have that completed we calculate the angle to send to the game by subtracting our new "refdefViewAngles[0]" from "angle2".

**Code:** angle_y=-(angle2+refdefViewAngles[0]);

Now that we have the two target angles, angle_x and angle_y, it is time to aim! I had mine set up with a simple aimkey, left shift...

**Code:** if(GetAsyncKeyState(VK_LSHIFT)&1)

{

*AngleX += angle_x;

*AngleY += angle_y;

}

And there you have it! A simple, yet effective method for head shots on your aimbot. This code is kind of long and drawn out, and it can surely be almost cut in half but I showed every detail here to make sure it made sense. Things to be added on to this code would be prediction, some kinda of visibilty check (obviously), and more vectors that would aim at players in various postions (ie. leaning, crouched, prone, etc.). This code will get 100% headshots ONLY when the target is standing!

Here is a link to a 3-D mathematics site that may help with some of the calculations I went through here:

http://chortlesu.edu/VectorLessons/vectorIndex.htmlBig thanks to Crx for letting me annoy him with my discussions/questions

Thanks to

**siLenCer**