That code is used to stop the AI trying to stand on top of each other when trying to melee the player - they sort of form a circle around you but of course if there's too many they will still pile up.
The bit you marked out is similar to the code I used to avoid each other, it works by getting an offset based on a given angle - in this case it uses their 'e' so most angles will be different (so a character of entity 1 would be looking to place himself at an offset of 50units 1° in front of the player... Therefore entity 180 would try to place himself behind the player.
only works on a flat (2D) circle but as they're limited by the terrain/player height anyway it's fine
also remember this code is only used if there's more than 1 AI in close range to the player and the AI in question is not already in melee range... otherwise entity 180 would continuously try to move behind the player while the player is trying to aim at him
My code follows the same logic except I try to work out the obstacles velocity so the character attempts to move behind the obstacle (so as to avoid walking into their path) and (most) can be found in the moveandavoid function.. I'll post the code snippet (though it won't run with just that) and the fpm (just a bunch of AI on the same path)
edit;
my code is the second half of this block (found in module_combatcore.moveandavoid())
if g_Entity[e]['avoid'] == 2 or (g_Entity[e]['avoid'] == 1 and stopstate ~= ai_state_startpatrol) then
ai_bot_substate[e] = math.random(1,2)
if ai_bot_substate[e] == 1 then
tAvoidAngle = AIGetEntityAngleY(AIObjNo)-95
else
tAvoidAngle = AIGetEntityAngleY(AIObjNo)+95
end
tAvoidAngle = (tAvoidAngle / 360.0) * 6.28
tAvoidX = GetEntityPositionX(e) + (math.sin(tAvoidAngle) * 30)
tAvoidZ = GetEntityPositionZ(e) + (math.cos(tAvoidAngle) * 30)
AIEntityGoToPosition(AIObjNo,tAvoidX,GetEntityPositionY(e),tAvoidZ)
StartTimer(e)
else --extra avoidance of other characters
if g_Time < avoid_time[e] then
AIEntityGoToPosition(AIObjNo,ai_bot_targetx[e],ai_bot_targetz[e])
SetRotation(e,0,AIGetEntityAngleY(AIObjNo),0)
else
--settings for the avoidance pathing
local avoidance_time = 50
local raydist = 120
local yoffset = 15
local obsray = module_combatcore.checkentityrays(e,raydist,0,AIObjNo,yoffset)
if obsray == nil then obsray = 0 end
if obsray > 0 and GetObjectExist(obsray) > 0 then
local obsE = P.ObjectToEntity(obsray)
if obsE ~= nil then
--PromptLocal(e,"Avoiding entity "..obsE)
local nex = GetEntityPositionX(obsE)
local nez = GetEntityPositionZ(obsE)
if velox[obsE] == nil then velox[obsE] = 0 end
if veloz[obsE] == nil then veloz[obsE] = 0 end
local oangy = module_combatcore.getangletopoint(obsE,nex+(velox[obsE]*1000),nez+(veloz[obsE]*1000))+180
oangy = (oangy / 360.0) * 6.28
ai_bot_targetx[e] = GetEntityPositionX(e) + (math.sin(oangy) * 30)
ai_bot_targetz[e] = GetEntityPositionZ(e) + (math.cos(oangy) * 30)
avoid_time[e] = g_Time + avoidance_time
end
end
end
end
plus a little bit extra to work out the velocity each frame at the top of the same function
--work out this entity's velocity so we know which way it is heading (used to try move around behind it when avoiding)
local tex = GetEntityPositionX(e)
local tez = GetEntityPositionZ(e)
velox[e] = tex - oldx[e]
veloz[e] = tez - oldz[e]
oldx[e],oldz[e] = tex,tez
the rest of the file is stock code (plus any set up and file reference changes)