1. Trouble with the game?
    Try the troubleshooter!

    Dismiss Notice
  2. Issues with the game?
    Check the Known Issues list before reporting!

    Dismiss Notice
  3. Before reporting issues or bugs, please check the up-to-date Bug Reporting Thread for the current version.
    0.30 Bug Reporting thread
    Solutions and more information may already be available.

Custom AI in cars

Discussion in 'Troubleshooting: Bugs, Questions and Support' started by savvas94, Aug 27, 2015.

  1. savvas94

    savvas94
    Expand Collapse

    Joined:
    Jun 28, 2015
    Messages:
    3
    Hello.

    I wanted to do develop some AI algorithms on how to make a car drive itself, so I found BeamNG engine and it seems perfect for me. But I really have no idea on how to do that. I asked on the FB page and they told me I can use Lua scripting, but still didn't understand where I should write code and how it would interprete with the game. Can you help me understand where to start?

    I should notice that I study Computer Science, so I know how to write code. I'm just stuck on how I can use my code on the game.
    *I don't know if it's a problem, but I only have the demo version and if I find a way to do my job I might buy the game for more capabilities.

    Thanks for your help!
     
  2. TheHattonator

    TheHattonator
    Expand Collapse

    Joined:
    May 15, 2015
    Messages:
    6
    You might be forced to buy the full game because I don't believe the AI is a 'thing' at all in the trial version, I'm guessing it would be much easier to modify the existing AI rather than to create in completely from scratch. Also, I don't believe you can install mods on the trial version of the game, which would be how you implement your custom features into the game.

    EDIT: I suppose you could create a AI controller, as in the AI decides which keyboard controls to send to the game, this would be a way of possibly creating AI, outside of the game, not sure.
     
  3. savvas94

    savvas94
    Expand Collapse

    Joined:
    Jun 28, 2015
    Messages:
    3
    Well, I cannot buy the game if I don't have reassurance that it will do what I want...
    And yes, I think it's impossible to install mods in trial.

    That was one of my thoughts, but still I need some guidance on how to do it. For example, how would the AI controller read data about speed, obstacles etc so as to decide its moves? :confused:
     
    #3 savvas94, Sep 1, 2015
    Last edited: Sep 1, 2015
  4. TheHattonator

    TheHattonator
    Expand Collapse

    Joined:
    May 15, 2015
    Messages:
    6
    Speed might be simple to get, you could provide some information to the code by manually driving the car and working out an acceleration time to speed ratio, possibly, or you might be able to get it from the game, not too sure about obstacles, you might find the program has to use a trial and error system, trying a variety of controls, and then another, until it finally works out a route to not hit obstacles, could be a way, I'm not 100% sure.
     
  5. savvas94

    savvas94
    Expand Collapse

    Joined:
    Jun 28, 2015
    Messages:
    3
    Well, that's a way to see it and make it work, but not what I intended. I would like my car to see the road (this could be done by knowing the curves etc or read obstacles realtime with some sort of sensor) and decide how to behave based on that! So yes, it's kinda tricky and quite possibly it won't be doable without the full version.

    EDIT: I mean, the AI has to drive the car by knowing what curves are next and not by memorising the route. Of course there can be some sort of trial and error but that's for different factors, like determining the amount of friction, acceleration power etc. So, if you know the car's handling and the next curves, then you can tell it when to brake and how much to steer with "simple" algorithms.
     
    #5 savvas94, Sep 1, 2015
    Last edited: Sep 1, 2015
  6. estama

    estama
    Expand Collapse
    Developer
    BeamNG Team

    Joined:
    Aug 7, 2012
    Messages:
    267
    In BeamNG, AI has a map of the terrain's roads (in the form of an overlaid graph with points and edges). It drives the car by using exactly the same controls as a human uses. It is also bound by exactly the same physics that the player has. The information that the AI knows at any one point are its position, velocity, direction of vehicle and G-forces that the vehicle is under (the same that a human would feel if he was driving the car).

    The whole AI code is available in one Lua file in /lua/vehicles/ai.lua. There are also some supporting algorithms for the AI (e.g. vector math, and graph path finding) that are also available in the /lua/common Lua code folder. So the whole thing is available as open source.

    Apart from the map data, AI has no "vision" API right now (to get a picture of what the driver sees), so it has to drive using the map. In the future, i have it in my plans to create a raycasting API so the AI will be able to also "see" the scene in front of it. This is mainly to be used when the AI goes offroading.

    The behaviors that have been implemented for the AI up to now are "stop", "drive to target", "flee from player" and "flee from player, while driving to target".

    Please note that, ai.lua is very complex code. Whenever i develop something new, i first make it work and then make it "nice". The code there is still in the "making it work" phase.

    Right now, the main things in my AI todo list are:
    - Better path optimization. Right now AI does not merge very well, its decisions for two close by turns.
    - "Chase player" AI behavior. Ideally if multiple AIs are chasing the player, i want them to coordinate with each other (e.g. one to chase from behind, and one to try to block in front of the player).
     
    #6 estama, Sep 16, 2015
    Last edited: Sep 16, 2015
  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