Lua trigger to measure driver’s reaction time

Hello, in beamng.tech, how to set a lua trigger that makes a car comes in front of me, so that I can measure the driver’s reaction time?
I tried asking AI GPT’s but I didn’t receive a functional answer/script.
Extremely urgent.
Thanks

Hi EngQ8,

Thanks for your question! To clarify and ensure we provide the most accurate support, are you asking how to programmatically spawn or move an AI-controlled vehicle into the user’s path in BeamNG.tech using Lua scripting during a driving simulation? Additionally, are you looking to record the user’s reaction time from the moment the event occurs to when the driver takes action (e.g., braking or steering)?

Hello, thank you for your reply.
Yes that is exactly what I want; I want a vehicle to come in front of the driver’s path when the driver passes a certain trigger. And I need to measure how much the driver brakes and steers to avoid collision, and to measure the reaction time.

Thank you

Dear EngQ8,

Here are the three main approaches using BeamNGpy for creating a car that appears in front of you for reaction time testing:

Option 1: AI Scripts (Recommended)

script = [
    {"x": -719.0, "y": 106.0, "z": 118.0, "t": 0.0},
    {"x": -758.0, "y": 67.0, "z": 118.0, "t": 5.0},
    {"x": -825.0, "y": 0.0, "z": 117.0, "t": 12.0},
]
cut_in_vehicle.ai.set_script(script)

Option 2: Direct Control

cut_in_vehicle.teleport(pos=(-100, 0, 142.8))
cut_in_vehicle.control(throttle=1, steering=0, brake=0)

Option 3: Waypoint Navigation

cut_in_vehicle.ai.set_waypoint("Bridge26_2")

Option 4: Flowgraph Editor

Use BeamNG Flowgraph for complex orchestration.

For reaction time testing, I recommend Option 1 - it provides precise timing control and reproducible results.

Best regards,
Abdul

Hello Asaeed

Thank you very much for your reply. I really appreciate it.

I will try your solutions and let you know.

Much obliged,

EngQ8

1 Like

Hi @EngQ8,
I just thought of something that might be useful for positioning the other vehicle that will face the player’s vehicle. You can use <vehicle>.teleport((x, y, z), reset=False) to place it directly in front of the driving vehicle.

Best regards,
Abdul