How to set up DIL scenarios?

The documentation claims to support “scenario-based testing capabilities” for “safety-critical scenarios with human input”. However, the sceneAI system doesn’t seem to have any way to program scenarios which respond to user input.

I need to set up a scenario where, for example, an AI car attempts to merge into the lane of the driver, causing a potential collision. And although lane-based driving is clearly implemented in ai.lua, it doesn’t seem to be exposed by the various ai modes available.

How can I program an ai vehicle to drive in the lane next to the user, match their velocity, and then change lanes into the user’s lane when cued (regardless of the exact speed that the user is driving)? I’m using flowgraph for my logic and am comfortable writing custom nodes.

Welcome to the community, @mHerring09!

There isn’t a “sceneAI” system in BeamNG.tech. For such a secanrio, it’s achievable through multiple options, i can speak about BeamNGpy, it’s a good option, you can run the scenario, attach the State sensor for tracking the stats of player vehicle and an optional IdealRadar sensor for V2V‑style awareness, and drive the AI via BeamNGpy.

The pattern is:

  • start the AI on a route with lane driving enabled (drive_using_waypoints(..., drive_in_lane=True, route_speed_mode="limit")),
  • each tick read the driver vehicle’s State and radar data to pace the AI (set_speed(player_speed, mode="set")).
  • on cue simulate the merge via a short scripted line/path (set_line) or import a trajectory from the ScriptAI Editor using import_script_ai_file and replay it with set_script.

If you need full low‑level control instead of AI, you can also drive the merging vehicle directly via Control API.

If you have any further questions or need additional assistance, feel free to reach out.

Best regards,
Abdulrahman Saeed
Research Software Engineer
BeamNG.tech Support Team

@asaeed Thanks for the help! When I said sceneAI I meant scriptAI. My question still stands.

In your solution, how would I generate this hypothetical “short scripted line/path” without being able to access information about the road’s lanes? For example, if I want to cue a lane change to the left, I would need a way to get a position on the lane to the left of the vehicle, but I don’t see a way to do that.

The only existing solution that I have found is to manually build a straight trajectory on each lane, and at the moment of my lane change to swap the vehicle from one trajectory to another. But with this solution, the vehicle makes an unrealistically fast lane change, since it is instantaneously attempting to move onto the trajectory of its neighboring lane.

I know that lane changes are implemented in ai.lua, since the traffic ai uses them. Is there no way to cue them manually?

Please advise.

Thanks for the clarification. Yes—manual, gradual lane changes are exposed via the in‑engine AI Lua API as laneChange (defined in \lua\vehicle\ai.lua), so you can trigger it directly from Lua or via Flowgraph. Alternatively, If you want to use BeamNGpy, if you want to compute lane offsets instead of swapping prebuilt lines, use the RoadsSensor, which provides centerline/edges, half‑width, curvature, heading, and numlane—enough to derive a smooth lateral target for a merge. Docs: RoadsSensor docs: BeamNGpy Reference — BeamNGpy documentation.

@asaeed, thank you for the help. I am still unsure of how to implement DIL scenarios. For the two solutions you’ve offered:

The laneChange function in ai.lua is not part of the documented interface. Because of its parameters (plan, dist, and signedDist), I am not sure that this function is used to trigger a lane change, rather it seems to be an internal planning utility. If I am mistaken, please explain how I can program a car to drive forward in its lane and then trigger a lane change using this function.

Also, the RoadsSenser, while useful, still doesnt seem to expose "a point in the next lane, d meters ahead”. From what I can tell it can only give me the point on the centerline of the current lane closest to the vehicle. Again, if I am mistaken, please elaborate.

It seems unusual to me that there isnt a simple way to program a vehicle to act in relation to the player. Are there any examples of these “safety-critical scenarios with human input” that the documentation claims to support?

Hello @mHerring09!

Thanks for the follow‑up. The ai.laneChange function is exposed in lua/vehicle/ai.lua, and it can be called from Flowgraph via a custom Lua node or from vehicle Lua.

If you want a basic example, here is an example that calls ai.laneChange directly. Load the West Coast USA map for this example:

That example shows the wiring and the call pattern. The key detail is that lane changes are computed on the AI plan, so the call needs to be made while the AI is actively driving with lane driving enabled. In practice, you should apply it continuously for a short window, not as a one‑shot call, otherwise the AI plan refresh can overwrite the displacement.

Recommended player speed: ~35 mph;

If you have any further questions or need additional assistance, feel free to reach out.