Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

AI Car on circuit avoiding dynamic obstacles (C#)

Discussion in 'Scripting' started by tulloch100, May 25, 2017.

  1. tulloch100

    tulloch100

    Joined:
    Apr 27, 2017
    Posts:
    59
    Hi
    I'm creating a kart racing game and want to have dynamic obstacles on my track that appear and I want to have the AI be able to avoid it pretty like what this video is doing


    Now I don't have any real programming knowledge so if someone could guide me in the right steps that would be great. The video says its using navmesh to be able to do this but I have no real idea what that is
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    The easiest way to do this is to have the AI estimate its course over the next few seconds and make sure blocks never spawn in its way. Boom, you're done, ship it!

    The next easiest way is to have the AI estimate TWO possible courses of action (maybe one car lane apart), and make sure a block only drops in one of those paths, then tell the AI to go to the other path when the block drops.

    The general case of making an AI avoid stuff like this in a way that seems reasonable (i.e., no 90-degree bends while travelling at high speed) is quite tricky. What if a cube drops so close in front of the AI that it has no "out?" What if the AI is already at the limits of traction control at the outer edge of the track and a cube drops there? Do you grant the AI super-traction to turn in tighter?

    The above items might help you think more clearly about the problem and how far into the rabbit hole of dynamic pathfinding you want to go, especially while maintaining a "reasonable-looking" physics simulation. Often games that use stuff like this make the objects breakable, but they impart a penalty to the person who hits them. That way an AI hits them, loses some of its speed, the block explodes, and the AI can continue, accelerating back up to speed. That solution is FAR easier to implement, simply by doing the above steps in a row.