Quote: "It's looking good so far! I'm working on a similar project and I'm curious how you're tackling the AI? Any tips or tricks for writing AI for flight based NPC's, or a starting point to work from?"
Thanks. Writing the AI is always challenging! This is the approach that I took:
1. The first thing to do is to get the enemy ships to be able to yaw, pitch in their target's direction. Position a dummy object at the AI ship's position and angle. Use the SetObjectLookAt command to look at the target. Work out the difference in angles between the AI ship and the dummy object. Use that information to rotate the AI ship. Once you've got this to work well move onto the next step:
2. Avoiding other objects. The AI are sending out a collision test ahead of them by enough distance to be able to react to it. If there is no collision, the AI simply continue with the logic in step 1 trying to point directly at their target. If there is a collision detected the AI send out a second collision test that is not directly ahead, but at an angle obtainable by the ships pitch and yaw limits. If another collision is detected, the angle is changed and the test will be tried again during the next game loop. Once no collision has been detected, the AI will set this position as a waypoint. The AI ship will then go back to the logic in step 1, but for lining up the waypoint rather than its actual target. Once the AI ship has reached the waypoint, the target is reset to it's original target and the whole cycle begins again.
3. Preset manoeuvres. Once the AI can avoid and react to other objects in the game world you can start to add a bit of character to their flying by using some preset manoeuvre patterns. E.g. Clockwise roll and full pitch for 100 game loop cycles. All the time the AI ship is doing the manoeuvre it is not doing step 1, but only step 2. If a collision is detected the manoeuvre is cancelled and the ship returns to the regular step 1 and 2 cycle.
I hope this helps.