我有两点,一个起始位置和一个目标位置(动态)。我想像在一级方程式比赛中一样培养球员。即第二个在第一个的右边和后面,第三个在第二个的左边和后面,依此类推。我已经确定了角度,所以他们面向目标点。
我不知道如何相对于轴上的线移动。我认为我的距离将它侧向移动,但我不是 100% 确定.. 我也太愚蠢了,无法弄清楚如何垂直于新点,即使它可能只是在某处添加了一个减号。
好吧,我希望有人可以帮助我解决这个问题,非常感谢。
注意:代码使用 Pawn,一种类似 C 的脚本语言。
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--;
}
}
}