Getting Player's Camera Look At
#1

Is there any function to check where does the player's camera looks at?
Kind of like GetPlayerFacingAngle.
Reply
#2

Did you search the forums at all? This has been asked many times. If you searched the wiki, you would have found this:

https://sampwiki.blast.hk/wiki/GetPlayerCameraFrontVector

This requires working with mathematical vectors. Let me know if you need some assistance.
Reply
#3

Ok You Should Use:
Код:
SetPlayerCameraLookAt
Then Set It How You Want .. With Numbers
Reply
#4

Thanks samgreen, I do need some assistance with it.
I'm trying to check if the player is looking at some point, and do something if he does.

This is the code:

pawn Код:
stock IsPlayerLookingAtFire(playerid, fireid)
{
    new
        Float:cX, Float:cY, Float:cZ,
        Float:cPosX, Float:cPosY, Float:cPosZ,
        Float:x1, Float:y1, Float:z1,
        Float:x2, Float:y2, Float:z2,
        Float:dX, Float:dY, Float:dZ;
    GetVehiclePos(GetPlayerVehicleID(playerid), x1, y1, z1);
    GetPlayerCameraPos(playerid, cPosX, cPosY, cPosZ);
    GetPlayerCameraFrontVector(playerid, cX, cY, cZ);
    x2 = FireInfo[fireid][firePosX];
    y2 = FireInfo[fireid][firePosY];
    z2 = FireInfo[fireid][firePosZ];
    new Float:Dist = GetDistanceBetweenPoints(x1, y1, z1, x2, y2, z2);
    dX = cPosX + floatmul(cX, Dist);
    dY = cPosY + floatmul(cY, Dist);
    dZ = cPosZ + floatmul(cZ, Dist);
    if(GetDistanceBetweenPoints(x1, y1, z1, dX, dY, dZ) <= 50.0)
    {
        return true;
    }
    return false;
}
I never worked with cameras before (Except doing the class screen).
The problem in this code is: wherever I look, it does something, doesn't matter where am I looking at, though it supposed to do something when I'm looking at the exact point.
Reply
#5

pawn Код:
if(GetDistanceBetweenPoints(x1, y1, z1, dX, dY, dZ) <= 50.0)
50.0 is quite a lot, you could look in the completely other direction and it would return true.
Reduce this to something between 5-10 if you want to check if the player looks in the area around the fire, and 2-4 for having it excactly at the middle of the screen
Reply
#6

Its not the point, anywhere I look, it does something (which shouldn't happened)
Just if I look at some point
Reply
#7

Yes, thats what i mean. The script creates a point with the same distance to the player as the fixpoint (the fire), but in the direction the player looks at. Then it calculates the distance between those two points. If it is below 50, it will return true.
But if you are e.g. 20m away from the fire, you can look anywhere, because the distance between them can be maximal 40m, if you look in the complete opposite direction of the fire.
So set it to a value like the ones i posted before, and it will work.

e.g.
pawn Код:
if(GetDistanceBetweenPoints(x1, y1, z1, dX, dY, dZ) <= 5.0)
Reply
#8

still.. no matter where I aim, even if I'm not looking at any fire at all, it does the same result, just in a lower distance
Reply
#9

Ah, got it:

pawn Код:
GetVehiclePos(GetPlayerVehicleID(playerid), x1, y1, z1);
//...
dX = cPosX + floatmul(cX, Dist);
dY = cPosY + floatmul(cY, Dist);
dZ = cPosZ + floatmul(cZ, Dist);
if(GetDistanceBetweenPoints(x1, y1, z1, dX, dY, dZ) <= 50.0)
You compare the calculated point to the vehicle pos, not the fire pos. Replace the x1,y1,z1 in the upper line by x2,y2,z2 (and do <= 5.0 or 10.0 as well)
Reply
#10

I don't even know if the code is right, I just need to check if player's camera is facing the fire
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)