Angle from Coordinates
#1

I've run into some problems with a racing script.
I want the player to be angled towards the next checkpoint, is this possible to get from the checkpoint coordinates?
If so, how?

pawn Код:
cp = player_cp[playerid];
if(cp == cps) nextcp = 0;
else nextcp = cp + 1;

x = race_cp[cp][0];
y = race_cp[cp][1];
z = race_cp[cp][2];

x2 = race_cp[nextcp][0];
y2 = race_cp[nextcp][1];
/*angle = ... ? */
Reply
#2

You can do it if race is starting onfoot u can use
pawn Код:
setplayerfacingangle
Reply
#3

This returns a 2D angle between 2 points. From point A (first 2 args) to point b (3rd and 4th args).

pawn Код:
stock Float:PointToPoint(Float:X, Float:Y, Float:PointX, Float:PointY)
{
    new Float:Angle;
    if(X > PointX && Y > PointY)
        Angle = floatabs(atan2(floatsub(PointX, X), floatsub(PointY, Y)));
    if(X > PointX && Y <= PointY)
        Angle = floatadd(floatabs(atan2(floatsub(Y, PointY), floatsub(PointX, X))), 270.0);
    if(X <= PointX && Y > PointY)
        Angle = floatadd(floatabs(atan2(floatsub(PointY, Y), floatsub(X, PointX))), 90.0);
    if(X <= PointX && Y <= PointY)
        Angle = floatadd(floatabs(atan2(floatsub(X, PointX), floatsub(Y, PointY))), 180.0);

    return Angle >= 360.0 ? floatsub(Angle, 360.0) : Angle;
}
Define or forward that function before using it.
Reply
#4

Thanks, iggy.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)