AI Pursuit Behavior

Discussion in 'Programming' started by bidwars, Mar 16, 2017.

  1. bidwars

    bidwars
    Expand Collapse

    Joined:
    Sep 23, 2014
    Messages:
    171
    I am trying some logic to allow ai to go after a target and calculate the position they will be in the future. Then turning the wheel to the new target position. The problem is that I don't get the correct results back. I am using the information from this website about pursuit and evade behaviors. https://gamedevelopment.tutsplus.co...ing-behaviors-pursuit-and-evade--gamedev-2946

    Here is what I have come up with so far.


    **********************************************************************************************************
    --aiVel2Target and aiTimetoTarget come from the ai.lua file.
    --vdata is the ai vehicle data
    --tdata is the target vehicle data


    local aiVel2Target = vec3(vdata.vel):dot((tdata.pos - vdata.pos):normalized())
    local aiTimeToTarget = (tdata.pos - vdata.pos):length() / (aiVel2Target + 1e-30)

    --pursuit logic from gamedevelopment.com
    local futurePos = tdata.pos + (tdata.vel * aiTimeToTarget)

    targetVec = (futurePos - vdata.pos):normalized()

    print(aiVel2Target)
    print(aiTimeToTarget)
    print(futurePos)
    print(targetVec)

    print(dirDiff)

    --calculate a new steering wheel position for the ai
    local dirDiff2 = math.asin(dirVec.x * targetVec.y - dirVec.y * targetVec.x)

    if dirDiff2 > 0 or dirDiff2 < 0 then
    dirDiff = dirDiff2
    print(dirDiff2.."new diff")
    end

    ********************************************************************************************************
    Results
    230.81024|A|GELua.print|vec3(-0.36776748664375,-0.92991523141565,0.002176728948314)
    230.81029|A|GELua.print|-0.075835180804463
    230.81032|A|GELua.print|-473.2302927265
    230.81035|A|GELua.print|vec3(824.26627325285,3063.0274744736,72.979271442529)
    230.81038|A|GELua.print|vec3(0.21071781268679,0.97754466518054,-0.0021049925328699)
    230.81040|A|GELua.print|-1.498599470887
    230.81042|A|GELua.print|1.3350355973452new diff
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice