Get Coords between 2 players
#1

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.
Reply
#2

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
Reply
#3

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.
Reply
#4

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

https://sampwiki.blast.hk/wiki/GetPlayerCameraFrontVector
Reply
#5

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..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)