OnPlayerLookAtPlayer
#4

Yes it should

@theory
But if you only calculate the distance between line and point you didn't count the distance to the player at all
If player2 is near player1 and 5m away from the camera center of player1 than he is far more of the screen than player3 who is pretty far way from player1

To make it more accurate you should norm if afterwards [(distance point to line) / (distance player 1 instersection)]
@theory end

Just wrote some code, didn't test that but it compiles so give it a try
pawn Код:
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);
}
pawn Код:
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;
}
Reply


Messages In This Thread
OnPlayerLookAtPlayer - by Om3n - 07.02.2015, 12:52
AW: OnPlayerLookAtPlayer - by Nero_3D - 07.02.2015, 13:29
Re: OnPlayerLookAtPlayer - by Om3n - 07.02.2015, 15:37
AW: OnPlayerLookAtPlayer - by Nero_3D - 07.02.2015, 18:13
Re: OnPlayerLookAtPlayer - by Tamer - 07.02.2015, 18:15

Forum Jump:


Users browsing this thread: 3 Guest(s)