# SolvedAimbot Math Trigonometry

#### Solaire

##### Respected Hacker
Dank Tier VIP
I've been at this for a week now, and I finally understand trigonometry enough to get a majority of the math. I've pieced together a lot of source, and learned a lot. My only issue is trying to set up the aimbot maths. A lot of them include after atan2(deltaX/deltaY) more math such as * 180 / 3.14 + 180.0f; Pic Here
(My beautiful drawing)

For the piece I drew, the math would be tan YAW = O/A
From maxdd's aimbot geometry tutorial, the YAW = tan((src - dst) / (src - dst))

He uses angles = 90.0f + (float)(atan2f(deltaX, deltaZ) * 57.29577513082f); for getting the YAW in AssaultCube. My issue is when I use this, if I'm left and going left of the enemy, it pushes the camera further left. Same with right and going right.

I'm not quite sure how to fix this, and I've tried just about everything I can think of. (Including different methods from maxdd's). My big question here is how do I solve for each of the sectors? I can get the first part, it's the putting it in the specific range that I'm having trouble with (0 - 90, 90 - 180, 180 - 270, 270 - 360).

The yaw goes from 0-360, and pitch from -90 to 90 (I have the pitch working).

Last edited:

#### Rake

I have know idea if this will help but I was reading about it last night
Is Assault cube based on left or right handed cartesian coordinate system?
The Unreal Engine uses a left-handed Cartesian coordinate system, so by definition the positive Y axis is on the right side. ("left-hand rule": if the index finger of your left hand points forward, the thumb upwards, then the middle finger must point to the right)
First apply the yaw component by rotating around the Z axis (the thumb) to the right for positive or left for negative values. (turn the index finger towards the middle finger for positive values)

• #### Solaire

##### Respected Hacker
Dank Tier VIP
From what that looks like, I think left. The yaw never goes negative, though. So maybe I should go from +360, to +90, to +180, to +270?

EDIT:
I was able to finally solve it. I had to change the "* 180.0f " after each atanf to a negative, then change the math for two of the sectors. Here is the working math for OpenGL aimbots (Where it's XYZ, not XZY).

Credits to a TON of sources on the internet. This is a mashup of a lot of different people works.

C++:
``````void CalcAngle(float *src, float *dst, float *angles)
{
float deltaX = (src) - (dst);
float deltaY = (src) - (dst);

if ((dst) > (src) && (dst) <= (src))
{
angles = atanf(deltaX/deltaY) * -180.0f / pi;
}

else if((dst) >= (src) && (dst) > (src))
{
angles = atanf(deltaX/deltaY) * -180.0f / pi + 180.0f;
}

else if((dst) < (src) && (dst) >= (src))
{
angles = atanf(deltaX/deltaY) * -180.0f / pi - 180.0f;
}

else if((dst) <= (src) && (dst) < (src))
{
angles = atanf(deltaX/deltaY) * -180.0f / pi + 360.0f;
}

float deltaZ = (dst) - (src);
float dist = sqrt(
pow(double(dst - src), 2.0) +
pow(double(dst - src), 2.0) +
pow(double(dst - src), 2.0));

angles = asinf(deltaZ/dist) * 180.0f / pi;
}``````

This has been a very amazing learning experience, and I'm glad I was finally able to solve it! I hope anyone who experiences the same issues is able to take from this code and learn.

Last edited:
• #### Solaire

##### Respected Hacker
Dank Tier VIP
In regard to viewangles
X,Y,Z = Pitch, Yaw, Roll
Angle = Pitch
Angle = Yaw
Angle = Roll

That's how your aimbot works with assault cube correct?
I only use the first two angles, and write 8 bytes instead of 12. The last isn't really needed. angles is the Yaw (Left-Right), angles is the Pitch (Up-Down). The XYZ used in the calc angle are the players positions. In data, the viewangles are stored mouseX, then mouseY, then roll.

Attention! Before you post:

99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

• Fill out the form correctly
• Tell us the game name & coding language 