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

What's the best way to make airplane AI?

Discussion in 'Navigation' started by DroidifyDevs, Jan 13, 2016.

  1. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    Hi there!

    So I'm making a racing airplane game, and I need a simple AI enemy plane to follow a pre-defined course and change its speed depending on the player's position. For example, if the player is too far ahead, the AI should speed up. So far I've read up on the Unity built in AI, and it probably won't work for 2 reasons:

    1: I can't change the tilt on the airplane in my scripts. So when the enemy plane makes a hard turn, the wings stay flat and looks horribly unrealistic. I can't find a way to tilt it since there isn't a script for the NavMeshAgent.

    2: Since I can't edit the NavMeshAgent script, I can't make the plane change speed either. Bummer :/

    So my question is, how do I make AI airplane that will fly on a pre-defined path but change its speed according to the player's position? So far I see that Unity's built in AI probably wont work... any ideas?
     
  2. Kukuruz

    Kukuruz

    Joined:
    Jan 8, 2014
    Posts:
    7
    Hello.

    Have you tried imple simple steering behaviours?
    Since your path is predefined it is quite easy to use a Path Following steering behaviour. You can make it follow the path strictly or with some deviation (for more natural look). Depending on the realism you need, you can combine different behaviours, each with its own weight in the equation.
    As for speeding up when too far behind, you can use the distance between the AI and the Player to scale your maximum speed.

    If you are not familiar with Steering Behaviours, here is a source that will help: http://www.red3d.com/cwr/steer/