Detecting if a player is infront or behind a player
#3

Assuming that GTA SA is one big coordinate plane with X and Y, then (0,0) is right in Blueberry.

Quadrant I is (+,+) [Top Right = Las Venturas area]
Quadrant II is (-,+) [Top Left = San Fierro, Bayside, etc.]
Quadrant III is (-,-) [Bottom Left = Missionary Hill, Angel Pine, Mount Chiliad, etc.]
Quadrant IV is (+,-) [Bottom Right = Los Santos]

By applying a basic algebraic algorithm, you can determine which quadrant Player A resides in, and then do an appropriate calculation to determine which player is in front of which based on their facing angles.

I'll lay out a piece of it for you (because i'm certainly not going to do it all for you, then you wouldn't learn anything).

stock GetPlayerMapQuadrant(playerid)
{
new Floatx, Float: py, Floatz;
GetPlayerPos(playerid,px,py,pz);

if(px >= 0)
{ // Top
if(py >= 0) return 1;
else return 2;
}
else
{ // Bottom
if(py >= 0) return 4;
else return 3;
}
}
--

Using this quadrant function, you can determine what kind of trigonometry you have to apply to get your answer. I'll give you a hint:
- You're going to want to basically imagine three points - One at (0,0) in Blueberry, one at player A and one at player B.
- This angle must be a right angle, because it assumes straight-line distance from Blueberry and straight-line LOS from Player A to B (thus creating a right triangle in various orientations).
- Because it is a right triangle, you can apply various trig theorems on it - that is what you need to figure out.

There's your hint! Good luck!
Reply


Messages In This Thread
Detecting if a player is infront or behind a player - by Puppy - 19.06.2015, 14:52
Re: Detecting if a player is infront or behind a player - by Lajko1 - 19.06.2015, 15:57
Re: Detecting if a player is infront or behind a player - by Lawbringer - 19.06.2015, 16:27

Forum Jump:


Users browsing this thread: 1 Guest(s)