Simple airplane AI

Hey guys, i'm making my first full game, and i'm in the hardest part(i think), it's the implementation of AI. In one part of my game, i need to destroy and airplane, using my airplane's machine gun and rockets. I'm trying to implement an AI system to my enemy airplane. Basically i want to make something like this: The airplane goes flying around some waypoints(i already have the waipoints script), but if the player has reached a certain distance, he stops to defend his "territory" and starts to chase me. But it's not as simple as it sounds, i know how to do this, but how can i do this and use the same physics of my airplane? For example, i have the airplane script to control my own airplane, but how can i "mix" these script to use in non-playable airplanes?

Thank's and hope you guys can help me!

I can't post my airplane script here, cuz it has been bought, and i think i can't post is here :D

i to am trying to learn how to do this except i want the plane to fly over my characters head when i go to the trigger point but i cant find the correct code for it any chance of help with this

@Henrique Dantas
You can use the Vector3.Distance() function to calculate distance
As for the AI itself, split it up into 3 sections - the enemy is either chasing you, dodging an object in it’s path or running away from you
I would give you he whole script but I’m still writing it myself
Hope this gives you a bit of a starter point

Have a collider with the “Is Trigger” checkbox marked. Write a script that uses the OnTriggerEnter() function, so that when your character moves into the collider the function is called
When the function is called, use GameObject.Instantiate() to create the plane at a preset position and rotation.
You then only need to write a very simple script that moves it wherever you want it to go
Hope this helps - let me know if you need more help, or if I misunderstood your problem :slight_smile: