
Originally Posted by
Orinion77
Hm your ClampAngle functions is weird.. Try this:
Code:
float flAngleNormalize(float angle)
{
while (angle < -180) angle += 360;
while (angle > 180) angle -= 360;
return angle;
}
Vector ClampAngle(Vector angles){
angles.y = flAngleNormalize(angles.y);
angles.x = flAngleNormalize(angles.x);
if (angles.x > 89.0f)
angles.x = 89.0f;
if (angles.x < -89.0f)
angles.x = -89.0f;
angles.z = 0;
return angles;
}
The clamp angle function was a NaN check together with a normalize angle function and a clamp function. Like @
Orinion77 suggested, split it up in 2 parts. Everytime you perform operations with any angle, normalize them. ( bla = a - b; normalize( bla ); ). Clamp them once, right before you set your viewangles.
The problem you're probably expiriencing is the while loop.
Code:
int Aimbot(void)
{
while (true)
{
Sleep(1);
{
int entindex = ClosestEnemyToCrosshair(90.f);
DWORD LocalPlayer = Read <DWORD>(clientDLL + dwlocalplayer);
Vector3 origin = Read<Vector3>(LocalPlayer + m_vecOrigin);
Vector3 vecview = Read<Vector3>(LocalPlayer + m_vecViewOffset);
position.x = origin.x + vecview.x;
position.y = origin.y + vecview.y;
position.z = origin.z + vecview.z;
while (GetAsyncKeyState(VK_XBUTTON1))
{
Vector3 punch = Read<Vector3>(dwlocalplayer + m_vecPunch);
Vector3 angles;
DWORD entitybase = Read<DWORD>(clientDLL + dwentitylist + (entindex * 0x10));
Vector3 pos = BonePos(entitybase, bonematrixoffset, 11);
CalcAngle(position, pos, angles);
angles.x = angles.x - punch.x * 2.f;
angles.y = angles.y - punch.y * 2.f;
ClampAngles(angles);
if (angles.x == 0 && angles.y == 0)
continue;
DWORD clientstate = Read<DWORD>(engineDLL + m_dwClientState);
Write<Vector3>(clientstate + m_dwViewAngles, angles);
}
Sleep(1);
}
}
return 0;
}
Once you're getting to the bold part, you're looping for as long as you keep pressing the button. By the way, GetAsyncKeyState also returns a positive number when the key was pressed since the last call, you should bitshift the most significant bit to make sure you're only executing statements whenever you're pressing the key.
If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState.
The problem you're having is that you're not updating your position, which results in wrongly calculated angles. The angle which gets calculated is between your position before you got into the while loop and the current position of the bone of the entity.
If i were you, i'd exchange the while loop with an if statement. This would also fix the problem that you're aiming onto an entity far away when another entity got closer towards you, since you also not update the closest entity unless you let go of the key.
If you keep your while( GetAsyncKeyState ) loop, move the statements where you read out the information for your position etc into the while loop.