07.02.2015, 12:52
Hello, have anyone proper working OnPlayerLookAtPlayer function? i found it here one times but it was fully buged.
stock Float: GetDistranceBetweenLineAndPoint(Float: sx, Float: sy, Float: sz, Float: vx, Float: vy, Float: vz, Float: px, Float: py, Float: pz) {
px -= sx;
py -= sy;
pz -= sz;
return VectorSize(vy * pz - vz * py, vz * px - vx * pz, vx * py - vy * px) / VectorSize(vx, vy, vz);
}
stock IsPlayerLookAtPlayer(playerid, giveplayerid, Float: offset = 1.0) {
new
Float: cX,
Float: cY,
Float: cZ,
Float: gX,
Float: gY,
Float: gZ
;
if(GetPlayerPos(giveplayerid, gX, gY, gZ) && GetPlayerCameraPos(playerid, cX, cY, cZ)) {
new
Float: vX,
Float: vY,
Float: vZ
;
GetPlayerCameraFrontVector(playerid, vX, vY, vZ);
vX = GetDistranceBetweenLineAndPoint(cX, cY, cZ, vX, vY, vZ, gX, gY, gZ); // opposite
vY = VectorSize(gX - cX, gY - cY, gZ - cZ); // hypotenuse
vZ = floatsqroot(vY * vY - vX * vX); // adjacent
return (vX / vZ) < offset;
}
return false;
}