Get Coords between 2 players - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Get Coords between 2 players (
/showthread.php?tid=425597)
Get Coords between 2 players -
Om3n - 26.03.2013
Hello i have a problem. i want to know how to get coords between 2 players.
i know:
player 1 - x and y
player 2 - x and y
but i need to know coords what are 2 meters in front of player 1 and its between player 1 and player 2.
anyone knows how to calculate this?
image for explanation in attachments.
Re: Get Coords between 2 players -
dusk - 26.03.2013
pawn Код:
new Float:X,Float:Y,Float:Z;
GetPlayerPos(one playerid,X,Y,Z);
GetPlayerDistanceFromPoint(other playerid,X,Y,Z);
This works in my head.dunno about reality tho
Re: Get Coords between 2 players -
Om3n - 26.03.2013
ok now i know distance between players. but i need to know coords X and Y 2 meters in front of player 1 and it must be between player 1 and 2.
Re: Get Coords between 2 players -
telmo_ferreira - 26.03.2013
https://sampwiki.blast.hk/wiki/SetPlayerCameraLookAt
https://sampwiki.blast.hk/wiki/GetPlayerCameraFrontVector
Re: Get Coords between 2 players -
Babul - 26.03.2013
hm... you first need to calculate the angle for player 1:
pawn Код:
new Float:angle=atan2(player1x-player2x,player1y-player2y);
since you know the angle, you can use the sinus/cosinus and a radius (2 meters?) to calculate new x,y coordinates.
pawn Код:
new player1xoffset=2*sin(angle,degrees);
new player1yoffset=2*cos(angle,degrees);
since those are only the offsets (relative to the player), you need to add player1's coordinates (x and y) to the results.
maybe you need to use (-angle,degrees) when NPCs/players/objects are facing the wrong direction - the formula should be (almost) ok..