I have two points, one start position and a goal position(dynamic). I want to spawn players as they would in a formula 1 race. i.e the second a little to the right and back of the first, third left and back of the second and so on. I have already determined the angle so they face to the goal point.
I dont know how to move relative to the line on the axes. I think my distance moves it sideways, but im not a 100% sure.. I also am too stupid to figure out how to go perpendicular of the new points, even though it's probably just adding a minus somewhere.
Well, I hope someone can help me with this, thanks a lot in advance.
Note: The code is in Pawn, a C-like scripting language.
new x1 = RaceCheckpoints[0][0]//startpoint x
new y1 = RaceCheckpoints[0][1]//startpoint y
new x2 = RaceCheckpoints[1][0]//goalpoint x
new y2 = RaceCheckpoints[1][1]//goalpoint y
new dist = 2;
new pos = 0;
new x3, y3, x4, y4, a, b, norm;
x3 = (x1 + x2) / 2;
y3 = (y1 + y2) / 2;
a = y1 - y2;
b = x2 - x1;
norm = sqrt(a*a + b*b);
a = a / norm;
b = b / norm;
x3 = x3 + a * -dist;
y3 = y3 + b * -dist;
x4 = x3 + a * 2 * dist;
y4 = y3 + b * 2 * dist;
for(new i;i<MAX_PLAYERS;i++)
{
if(RaceParticipant[i] != 0)
{
if(IsPlayerInAnyVehicle(i)) PlayerVehicles[i]=GetPlayerVehicleID(i);
else PlayerVehicles[i]=0;
if (pos = 0)//left lane
{
SetPlayerPosFindZ(playerid, x3, y3, RaceCheckpoints[0][2]+10);
new angle = atan2(y2 - x3, x2 - y3) * 180 / PI;
SetPlayerFacingAngle(i,angle);
pos++;
}
if (pos = 1)//right lane
{
SetPlayerPosFindZ(playerid, x4, y4, RaceCheckpoints[0][2]+10);
new angle = atan2(y2 - x4, x2 - y4) * 180 / PI;
SetPlayerFacingAngle(i,angle);
pos--;
}
}
}