CSGO: Loosing aim target
VectorAngles(const Vector3& dir, Vector3 &angles)
{
float hyp = FastSQRT((dir.x * dir.x) + (dir.y * dir.y));
angles.x = atanf(dir.z / hyp) * M_RADPI;
angles.y = atanf(dir.y / dir.x) * M_RADPI;
angles.z = 0.0f;
if (dir.x >= 0.0)
angles.y += 180.0f;
}
NormalizeVector(Vector3& v)
{
if (v.x > 89.0f && v.x <= 180.0f)
v.x = 89.0f;
while (v.x > 180.f)
v.x -= 360.f;
while (v.x < -89.0f)
v.x = -89.0f;
while (v.y > 180.f)
v.y -= 360.f;
while (v.y < -180.f)
v.y += 360.f;
v.z = 0;
}
This is simple vector angle from double sdk for testing.
1. get bone position
2. get view angles
3. calc agle
4. normalize
5. write new angles
Why do i lose target when straving around the enemy and my angle passes 180?
My functions are pretty basic and seems to give solid results. Correct me if im wrong.
i mean it works great but at some point when i strave around the target playerangles are 180 and enemy angles are -180.
it seems that im not normalizing correctly or i have to normalize again.
here is how i get my angles:
// Reading Player Viewangles
ReadProcessMemory(Process, (LPVOID)(ClientStateBase + dwViewAngles), &Angle, sizeof(float[3]), NULL);
// Reading Player Position
ReadProcessMemory(Process, (LPVOID)(LocalPlayerBase + m_vecOrigin), &Position, sizeof(float[3]), NULL);
ReadProcessMemory(Process, (LPVOID)(LocalPlayerBase + m_vecViewOffset + 0x8), &Height, sizeof(float), NULL);
// Reading Enemy Bone Position and calc angles
if (ClassID == 35)
{
ReadProcessMemory(Process, (LPVOID)(BoneBase + 0x30 * Bone + 0x0C), &Position[0], sizeof(float), NULL);
ReadProcessMemory(Process, (LPVOID)(BoneBase + 0x30 * Bone + 0x1C), &Position[1], sizeof(float), NULL);
ReadProcessMemory(Process, (LPVOID)(BoneBase + 0x30 * Bone + 0x2C), &Position[2], sizeof(float), NULL);
Angle[0] = atanf((Player.Position[2] - Position[2]) / sqrt(Ppow(Position[0] - Player.Position[0], 2) + pow(Position[1] - Player.Position[1], 2))) * 180.0 / PI;
Angle[1] = atanf((Player.Position[1] - Position[1]) / (Player.Position[0] - Position[0])) * 180.0 / PI;
if (Player.Position[0] - Position[0] >= 0.0) { Angle[1] += 180.0; }
if (Angle[1] > 180.0) { Angle[1] -= 360.0; }
if (Angle[1] < -180.0) { Angle[1] += 360.0; }
isEnemy = true;
}
// Aim
Player.Angle[0] = Enemy[id].Angle[0];
Player.Angle[1] = Enemy[id].Angle[1];
WriteProcessMemory(Process, (LPVOID)(ClientStateBase + dwViewAngles), &Player.Angle, sizeof(float[3]), NULL);
..this is driving me crasy for ages now.
|