29.06.2011, 21:33
Hey,
I was doing some research on Game development. and I found a few things that could be usefull for samp.
Here's a quick one, its the dot product.
that means, it checks if a player is in someone else's field of view.
The default FoV(Field of View) is around 140, but you can change it while using it
Its untested, but i think my math is fairly good :P
Usage:
Good luck!
I was doing some research on Game development. and I found a few things that could be usefull for samp.
Here's a quick one, its the dot product.
that means, it checks if a player is in someone else's field of view.
The default FoV(Field of View) is around 140, but you can change it while using it

Код:
stock InFieldOfView(playerid, from, const radius = 140, const range = -1) { new result; new Float:x1, Float:y1, Float:z1, Float:a; new Float:x2, Float:y2, Float:z2; new Float:D1, Float:D2, Float:V1, Float:V2; GetPlayerPos(from, x1, y1, z1); GetPlayerPos(playerid, x2, y2, z2); GetPlayerFacingAngle(from, a); D1 = x1/sqrt(x1^2+y1^2); D2 = y1/sqrt(x1^2+y1^2); V1 = x2/sqrt(x2^2+y2^2); V2 = y2/sqrt(x2^2+y2^2); if(sqrt((x2-x1)^2+(y2-y1)^2) <= range && range != -1) { result = acos(D1*V1 + D2*V2); if(result <= radius) return 0; } return 1; }
Usage:
Код:
if(InFieldOfView(playerid, npc)) { //ATTACK NPC!! ATTACK!! }