A flying enemy AI. How to?

Hi guys.

So I have a little spaceship that I can fly around and shoot stuff with. I also have an enemy AI turret that shoots at me if im close enough. Now I want to make an enemy spaceship that would fly around a certain area, detect me when I am close and start chasing and shooting at me. I know there are tutorials about enemy AI, but they are all about enemies patrolling on the ground. Like I dont know how would I set up a nav-mesh in air? Can someone point me to the right direction or a nice tutorial please?

there are no built in 3d path finding yet, so you have to build your own.

relevant post on reddit

Hm not sure I can do it with my extremely limited knowledge of BPs. I’m gonna go ahead and ask you a stupid question. What if I put an invisible mesh with a nav mesh in air and make my enemy patrol there, but make it start following me when im close? Would the enemy refuse to leave the mesh if I would go below or above it? Does it sound like a doable thing at all?

Ty for reply mr

maybe with some cleaver switch you can do it like what you described.
Essentially a multi-layer nav-mesh with a sweep trace to see if you can go up or down a level.
The catch is, you can easily trap enemy if player found out how your path finding works.
(compare to A* that make sure AI can reach a place as long as a path exists.)

It’s an interesting concept to overcome limitation btw, so not a stupid question at all.
Navmesh actually rebuilds when scene changes
.unrealengine.com/latest/INT/Resources/ContentExamples/NavMesh/1_3/index.html
so maybe there is a good way to exploit that.

Ill explore my options and will see what I can do. Cheers!!!

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.

Thank you for an in depth reply, I really appreciate it. I guess I have my work cut out for me. Good thing that unlike my current job, I enjoy doing .

Hi again guys! So now I have an actor BP with an enemy ship who is attacking me when I am close. The problem is that its just hanging in the air and shooting at me. I tried to figure out how to make the enemy ship to fly where it is looking but I couldn’t make it work. I tried to make a character class BP and use character movement component, but it didn’t work. So I figured out that there must be a way to make an actor BP to move where it is looking at, but so far no luck in making it work. Here is a little video of how it looks: http://youtu.be/mSOJ1hlCLcU Everything in the video is placeholders. These are just basic models I slapped together in Blender while I wait for my mate to make the real stuff.

Any help would be greatly appreciated!

We have flying AI working just fine and it’s a lot simpler than you might initially think. Basically set all the physics modes to flying. Give it movement inputs along its forward vector to drive it and then simply use “set actor rotation” to guide it. I use a combination of random yaw/pitch for patrols or wandering or “find look at rotation” nodes with an RInterp for going to patrol points or chasing enemies. If you wanted it to stay within a radius, simply give it an actor to use as a center point and check the distance. If it goes out of range, have it look at the center point object and move forward. One handy tip on that is to set the distance check to lower when it gets out of range and keep it moving towards the point until the smaller check is fulfilled and then return the distance check back to its normal patrol radius. effectively makes it “check in” every once in a while.

Using the simple theory of “drive thing” like you’re controlling it should get you pretty far. Having it find a complex path through a maze towards an actor might prove a little difficult without a nav mesh but you could attempt something like a linked grid of volumes to help it out. You might be able to trace a path from your character to the mesh by simply running traces between volumes. I guarantee that it gets tricky and hairy, but with a simple map layout or just open sky, it’s totally simple.

Peter L Newton has a Flying AI template he will be sharing soon, you can see a video of it in action here:

Check out the projects on my channel i hope they help you
https://www.youtube.com/playlist?list=PL1lwA_g8dnUMFqFJ0UxjQcLxAC29Fwpre
https://youtube.com/watch?v=6Tffh9VvKz4
https://youtube.com/watch?v=wXq3rp4yOrQ