BeamNGpy AI ignores NPCs and collisions during Lane Following / Cut-in scenarios

Hello BeamNG community,

I am using BeamNGpy 1.32 to control an ego vehicle with the built-in AI.

In my scenario, an NPC performs a cut-in from an adjacent lane. However, the ego AI does not react (no braking or avoidance) and often collides, as if the NPC is not detected.

My setup is roughly:

self.vehicle.ai_set_mode(‘manual’)

self.vehicle.ai_drive_in_lane(True)

self.vehicle.ai_set_aggression(0.3)

self.vehicle.ai_set_speet(speed_ms, mode=’limit’)

self.vehicle.ai_set_waypoint(‘end_point’)

I also tried ‘traffic’ mode, but the ego vehicle still does not avoid/react to surrounding vehicles.

In my BeamNGpy version, AIApi only provides: set_mode, set_speed, set_waypoint, drive_in_lane, set_line, set_script, set_aggression (I don’t have drive_using_waypointsor avoid_cars).

Is the built-in AI expected to detect and react to vehicles during cuts-in, or is external sensor-based logic required for this scenario?

Thanks!

Hello @ali.gullu,
First, keep in mind that ai_set_waypoint automatically sets the mode to “manual”. The problem is, “manual” mode doesn’t automatically avoid cars, and “traffic” mode doesn’t accept a target to go to. In your code you can skip the ai_set_mode call, and instead add the following line: self.vehicle.queue_lua_command('ai.setAvoidCars("on")'). Let me know if that helps.