Originally Posted by
nertigelts
nearest hitbox like in p2c ..
Oh, just iterate through every entity, get their and your position. Get an angle from your position to the desired target. (Hint, CalcAngle). Compare the distance from every angle to your viewangles. (if the distance is less than it was before then make that your maximum distance and reset it after you've iterated through every entity.) The distance can be measured using the pythagorean theoriem.
Some code examples.
Code:
double dAimFov = MenuObjects::AimbotFOV.Get();
for (size_t i = 0; i < 32; i++)
{
KaninSDK::CBasePlayer* pEntity = reinterpret_cast<KaninSDK::CBasePlayer*>(pClientEntityList->GetClientEntity(i));
if (!pLocal)
continue;
if (!pEntity)
continue;
if (pEntity->GetHealth() < 1)
continue;
if (pEntity->GetTeam() == pLocal->GetTeam())
continue;
if (pEntity->bIsDormant())
continue;
Angle = CalcAngle(pLocal->GetHeadPosition(), pEntity->GetBonePosition(8));
NormalizeAngle(Angle);
double tempDist = GetDistanceToAngle(Angle, CurAngle);
if (tempDist < dAimFov)
{
dAimFov = tempDist;
vecTargetAngle = Angle;
}
}
Code:
double Get2DDistance(Vector vec1, Vector vec2)
{
return sqrt(pow(vec1.x - vec2.x, 2) + pow(vec1.y - vec2.y, 2));
}
Vector CalcAngle(Vector vecSource, Vector vecDestination)
{
Vector vecDelta = vecSource - vecDestination;
double Hypotenuse = sqrt(pow(vecDelta.x, 2) + pow(vecDelta.y, 2));
Vector vecTemp(
static_cast<float>(atanf(vecDelta.z / Hypotenuse) * RADPI),
static_cast<float>(atanf(vecDelta.y / vecDelta.x) * RADPI),
static_cast<float>(0.f));
if (vecDelta.x >= 0.f)
{
vecTemp.y += 180.f;
}
return vecTemp;
}
If you want the closest hitbox then I think that you can just iterate through every hitbox, same logic applies.