I'm working on some AI issues, and I need to approximate time when 2 pawns get exact distance between each other. I'm using this function but it seems not working. Could someone please help to correct the function?
We are inside AIController child when calling this function. Function FExchange simply swapping two float values.
Code:
function float GetDistanceTime(Pawn P, float PawnMoveDir, float PMoveDir, float Dist)
{
local float T,GST1,GST2; // Gather Speed Time - время за которое наш актор разовьёт максимальную скорость
local float StartVel1,StartVel2,MaxVel1,MaxVel2,Accel1,Accel2;
local float GSDist1,GSDist2;
local float GSDistBoth,GSDistOne;
local float A,B,C,D;
StartVel1 = VSize(Pawn.Velocity);
StartVel2 = VSize(P.Velocity);
MaxVel1 = Pawn.GroundSpeed * PawnMoveDir;
MaxVel2 = P.GroundSpeed * PMoveDir;
Accel1 = Pawn.AccelRate * PawnMoveDir;
Accel2 = P.AccelRate * PMoveDir;
GST1 = (MaxVel1 - StartVel1)/Accel1;
GST2 = (MaxVel2 - StartVel2)/Accel2;
GSDist1 = GST1 * GST1 * Accel1 * 0.5;
GSDist2 = GST2 * GST2 * Accel2 * 0.5;
if ( GST2 > GST1 )
{
class'AdminControlMut'.Static.FExchange(GST1,GST2);
class'AdminControlMut'.Static.FExchange(GSDist1,GSDist2);
class'AdminControlMut'.Static.FExchange(Accel1,Accel2);
class'AdminControlMut'.Static.FExchange(MaxVel1,MaxVel2);
class'AdminControlMut'.Static.FExchange(StartVel1,StartVel2);
}
GSDistOne = GST2 * GST2 * Accel1 * 0.5;
GSDistBoth = GSDistOne + GSDist2;
if ( Dist <= GSDistBoth )
{
T = sqrt(Dist * 2 / (Accel1 + Accel2));
return T;
}
StartVel1 = StartVel1 + Accel1 * GST2;
StartVel2 = MaxVel2;
T = GST2;
GST1 -= GST2;
GST2 = 0;
GSDist1 = GSDist1; // это ещё старые значения
GSDist2 += GST1 * MaxVel2;
if ( Dist <= GSDist1 + GSDist2 )
{
Dist -= GSDistBoth;
A = Accel1 * 0.5;
B = StartVel2;
C = -Dist;
D = B*B - 4*A*C;
D = sqrt(D);
GST2 = T;
T = (-B+D)*0.5/A;
if ( T < 0 ) T = (-B-D)*0.5/A;
return GST2 + T;
}
Dist -= GSDist1 - GSDist2;
GST1 += T;
T = GST1 + Dist / (MaxVel1 + MaxVel2);
return T;
}
We are inside AIController child when calling this function. Function FExchange simply swapping two float values.
Last edited: