Getting new XY coordinates
#1

So i have a coordinate, let's say:

x = 10, y = 2

And let's say i want to travel 20 "units" in 90° direction (west in-game).

What would be my new x and y?

Can you give me a snipet/function/explain how to do this?

Thank you.
Reply
#2

do /save [optional(name)]
goto savedpositions.txt in samp files
and get the new x y code
\Documents\GTA San Andreas User Files\SAMP
default
Reply
#3

pawn Код:
new Float:X,Float:Y,Float:Z,Float:Angle;
GetPlayerPos(playerid,X,Y,Z);
GetPlayerFacingAngle(playerid,Angle);
Then do what you want to do.
Reply
#4

I don't want to manually do it, i want the server to calculate it.

For instance a function like this:

GetDistanceXY(current_x, current_y, distance, angle)

And it returns the new x/y, which are "distance" far from current_x and current_y at "angle".
Reply
#5

pawn Код:
stock getNewCoordinatesInDirection(playerid, Float: fNewX, Float: fNewY, Float: fDistance = 2.0)
{
       new Float: fOldX, Float: fOldY, Float: fOldZ, Float: fAngle;
       GetPlayerPos(playerid, fOldX, fOldY, fOldZ);
       GetPlayerFacingAngle(playerid, fAngle);
       fNewX = fOldX + (fDistance * (floatcos(-(fAngle + 90), degrees)));
       fNewY = fOldY + (fDistance * (floatsin(-(fAngle + 90), degrees)));
       return 1;
}
You'll have to change
pawn Код:
-(fAngle + 90),
these lines in order to get the desired effect, because this is simple polar stuff, but I am unsure as to how the GTA: SA co - ordinates work.
Reply
#6

Thanks a lot, that will help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)