Getting setAiMode(nameOfCar, 'manual') to work

Discussion in 'Programming' started by sketchy_b, May 6, 2016.

Tags:
  1. sketchy_b

    sketchy_b
    Expand Collapse

    Joined:
    Apr 13, 2014
    Messages:
    61
    Does any one know any way of getting setAiMode(nameOfCar, 'manual') to work I have all waypoints set up but it never attempts to follow the route. however if I set the mode to flee that works just fine! please help

    here is my code

    local M = {}

    local running = true
    local scenario = nil
    local speed = 0

    local helper = require('scenario/scenariohelper')

    local function reset()
    running = false
    end

    local function fail(reason)
    scenarios.finish({failed = reason})
    reset()
    end

    local function success(speed)
    local result = {msg = 'Well done, your speed: '..string.format("%0.2f", speed * 3.6)..'km/h'}
    scenarios.finish(result)
    reset()
    end

    local function onRaceStart()
    reset()

    helper.init()
    helper.setAiMode('aiCar1', 'manual')
    helper.setAiRoute('aiCar1', {"ai_wp_1", "ai_wp_2", "ai_wp_3", "ai_wp_4", "ai_wp_5", "ai_wp_6", "ai_wp_7", "ai_wp_8", "ai_wp_9"})
    helper.trackVehicle('aiCar1', 'aiCar')
    helper.trackVehicle('scenario_player0', 'playerCar')

    running = true
    end

    local function onRaceTick(raceTickTime)
    if not running then
    return
    end

    helper.update(raceTickTime)

    local aiCarData = map.objects.aiCar
    local playerCarData = map.objects.playerCar

    if not aiCarData or not playerCarData then
    return
    end

    if aiCarData.damage > 0 and speed == 0 then
    speed = playerCarData.vel:length()
    end

    if aiCarData.damage >= 5000 then
    success(speed)
    end

    if scenario.timer > 18 then
    fail("You lost!")
    end
    end

    local function onScenarioChange(sc)
    scenario = sc
    end

    M.onRaceStart = onRaceStart
    M.onRaceTick = onRaceTick
    M.onScenarioChange = onScenarioChange

    return M
     
  2. Nadeox1

    Nadeox1
    Expand Collapse
    Spinning Cube
    BeamNG Team

    Joined:
    Aug 5, 2012
    Messages:
    14,685
    In your scenario, does the AI car have the same name as in the LUA?
    Same for the waypoints?
     
  3. sketchy_b

    sketchy_b
    Expand Collapse

    Joined:
    Apr 13, 2014
    Messages:
    61
    Thanks for the reply. Yea, the names all match up. I've tried so many things to get this going. But it never wants to follow the waypoints. Ill post my prefab code up here later so it can be compared. I can't do it now as not at home. Thanks in advance and to Nadeox1 for the reply
     
  4. Nadeox1

    Nadeox1
    Expand Collapse
    Spinning Cube
    BeamNG Team

    Joined:
    Aug 5, 2012
    Messages:
    14,685
    Is the AI car placed near the first waypoint? (better if very close).
    The waypoints also must form an actual route, else the AI will not know how to reach the nodes (it doesn't drive straight to them)
     
  5. sketchy_b

    sketchy_b
    Expand Collapse

    Joined:
    Apr 13, 2014
    Messages:
    61
    Yea, I've poured a fair few hours into this en-devour now and no luck. any chance you (or any one else who wants to) could take look for me? I've attached the scenario to this and it needs extracting and putting into my rally ridge level "documents/beamng/mods/levels/rallyridge" If I get this sorted I'll have a massive scenario update for my map. so I'm keen to work it out. Thanks in advance
     

    Attached Files:

  6. sketchy_b

    sketchy_b
    Expand Collapse

    Joined:
    Apr 13, 2014
    Messages:
    61
    Ok, I got it working just using the path nodes I already had laid down for my mesh roads. Still not sure why I couldn't get the AI to follow my custom set of markers.
     
  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