A flying enemy AI. How to?

It might seem like it’s flying if it’s just moving along an invisible mesh, but eliminating up and down movement makes flying rather a lot like walking somewhere. You could try making a cake of navmesh planes and using nav link proxies to move between them, but I’m not sure how smart that would be really.

You could however make your own flying 3d behaviour that is not dependant on a navmesh and use actor based obstacle avoidance in addition to just moving towards some target.
You could add constant movement to the enemy spaceship, then if it is not near a target that it can attack, make it move towards a designated point and periodically check if that point is close enough to your enemy spaceship, if so, change the destination point. Then if the player is in range, either make it move towards the player immediately (easy with “find look at rotation”) or use some kind of turn rate to turn the rotation of the enemy to face the player. And then you can make it return to the path following bit if the player is destroyed or no longer considered a threat.

That works when you have no obstacles. But if you do have obstacles, you can add some kind of collision detection in front of the ship and then add movement/rotation to one side when it detects a collision. Of course that works more for avoiding something like asteroids than getting around corners and such (which arguably don’t exist much in space, but still)

Even better though maybe would be to use some kind of line trace system to detect the shortest path with no collisions to the player and then move along that. (I tried using something similar for bending a rope around obstacles, but I ultimately discarded that idea for something better.) Like a trace “spiralling” out from the middle until another trace from that end location (if nothing is hit) can hit the player, then use that path to move somewhere. shows what I mean, it shows a spaceship doing traces to find valid path to target orange UFO. It’s on a 2D plane for ease of understanding, but you could do that in a triangle or a very segmented circle depending on the accuracy you want and the performance you can spare.

Of course something as simple as won’t be able to find anything hiding in a concave shape or behind multiple corners, but in a spacey game with maybe a few obstacles floating about and not much else, it could even function like . But don’t feel like you have to use a navmesh and the standard AI move-to commands. Even if it seems easier to start with those than making something more specialized (but considerably simpler) for the task yourself.