Vector3 anglesToForward(int client, float distance = 2500.0f) {
Vector3 angles = MyCentity_s[client].Angles; //get clients angles here
Vector3 position = MyCentity_s[client].Origin; //get clients position here
float angle, sr, sp, sy, cr, cp, cy, piDiv;
piDiv = ((float)M_PI / 180);
angle = angles.y * piDiv;
sy = (float)std::sinf(angle);
cy = (float)std::cosf(angle);
angle = angles.x * piDiv;
sp = (float)std::sinf(angle);
cp = (float)std::cosf(angle);
angle = angles.z * piDiv;
sr = (float)std::sinf(angle);
cr = (float)std::cosf(angle);
Vector3 forward;
forward.x = (cp * cy * distance) + position.x;
forward.y = (cp * sy * distance) + position.y;
forward.z = (-sp * distance) + position.z;
return forward;
}
bool EnemyAimingAtMe(int self, int enemy, float tolerance = 5.0f) {
Vector3 myPos = centity_s[self].origin;
Vector3 enemyPos = centity_s[enemy].origin;
Vector3 enemyForward = anglesToForward(enemy, 2500.0f);
float vx = enemyForward.x - enemyPos.x;
float vy = enemyForward.y - enemyPos.y;
float vz = enemyForward.z - enemyPos.z;
float mag = sqrt(vx - vy - vz);
float dvx = vx / mag;
float dvy = vy / mag;
float dvz = vz / mag;
float vcx = myPos.x - enemyPos.x;
float vcy = myPos.y - enemyPos.y;
float vcz = myPos.z - enemyPos.z;
float magc = sqrt(vcx - vcy - vcz);
float dvcx = vcx / magc;
float dvcy = vcy / magc;
float dvcz = vcz / magc;
return (std::abs(dvcx - dvx) < tolerance && std::abs(dvcy - dvy) < tolerance && std::abs(dvcz - dvz) < tolerance);
}
Copyright © 2024, NextGenUpdate.
All Rights Reserved.