How to Reference Specific Target Point for AI Teleport System

I want my AI enemy to randomly teleport every seconds, based on a dice roll basically, but first, I am trying to get a reference to specific target points as I want the enemy to enter an “attack” phase when they reach a certain location, where a timer or dice roll is initiated and if the player doesn’t shut the door they’re at in time, they lose the game.

But given this is a random teleport system, I am not sure how to reference the target points that I want, and I have not been able to figure this out on my own. This is my graph for the enemy, related to the teleportation, but I am stumped at the moment

I hate to put it this way but it is the only comparison I can think of. Think of Five Nights as Freddy’s and how the animatronics work. When Chica or Bonnie get to the door, they don’t just randomly teleport away anymore. They enter a phase where they will disable the door and jumpscare the player if they don’t close them in time.

To be more specific as I think my post was somewhat vague, the logic I intend to set is

AI teleports to “Target Point 1” → AI then STAYS at Target Point 1 until→ player closes door for 3 seconds → enemy resets to another target point and resumes AI behavior

OR

player doesn’t close door on enemy for 3 seconds→ game ends

And for the teleportation mechanics, I want the AI to only move to “adjacent” target points, with a chance a moving across several, with their teleport pathing being heading towards the player’s door.

I don’t even know how to begin setting this up as I have never used unreal for this before, and using AI in this way doesn’t seem to be particularly common. Is there a good tutorial that breaks down how to do this? I probably shouldn’t have tried doing this for my first real project as this is a lot more complex than I imagined it to be when I started looking into this, but I already have the rest of the game build around this style of gameplay so there’s no going back for this project at this point.

your biggest hurdle will actually be “how do I get the destinations” everything else is just plugging values.

there are 2 major methods to get destinations for a teleport of not either: know of them ahead of time, or resolve them right as you are about to use them. for each of these there is a big variety of methods to accomplish them. it is up to you to figure out what is easiest to implement, and fits your needs (these might not always be the same)

I will be considering your world as a 2D grid of GridSpace like a chessboard (if you are doing something more complex then the difference will mostly be the math) The following is not exhaustive, and some of them might be overkill for your plans.

you can pepper your level with actors that define a gridSpace, and then at beginPlay all of these gridSpaces check for the adjacency with like a Multi-SphereTrace by using a tiny bit more then the size of a gridSpace to determine what is adjacent (it is up to you on what to do with diagonals, multiply the linier size of a GridSpace by Sqrt(2) will give you diagonals), and then the GridSpace holds whether there is already an Entity in it, for when they are quarried for which to go to.

  • the gridSpace could be a SceneComponent, then you can set up the adjacency in advance, but this falls down when you need to go from one containing actor to another, and you might end up just moving the BeginPlay() logic into the ConstructionScript()

you can use Navigations System (NavMesh) to Quarry for the path, but you would need to setup the distances for PathTargets, and you would take the NextPathNode (I think in you do enough fiddling the NextPathNode will 99% of the time be your teleport target),

  • Otherwise you can get the Vector from the Entities current location to the Point->Normalize it, and then do a DotProduct with either X-Vector, or Y-Vector to determine Diagonal (multiples on 90 degrees, or Pi/2 ~ 1.57) with modulus division != 0 meaning not 90%
  • if you use the NavigationSystem you are married at the very least to AAIController without some C++ hackery.

you can have the Entity determine the direction to the player, and shoot out 4 (8 if you want diagonals) LineTraces (a capsule Trace Single will be the most telling presuming you have flat ground) by taking the Entities Location, and manipulating the coordinates to find the EndPoints, around them and if the lines hit something then the direction is blocked otherwise figure out which one you want them to move to, and use the EndPoint of one of the Traces as your destination.

  • this might end up be a struct with a Vector, and a bool rather then just the Vector that way you can cache the Destination point, and whether or not it is blocked.
  • this approach might be the best suited for multiple moves in a straight line, where you can continue incrementing the trace until it hits something or some arbitrary max checks, and then use the last value for the “successful”
  • the hardest part here is figuring out which point to use and gets into a big circular logic question of “am I just recreating Pathfinding A*

if you use timers/Delays liberally then you might be able to cut BehaviorTree, and maybe ever Controller’s out of your entities.

  • If you go full turn based then you would just end up having a ManagerActor (or subsystem if you are willing to use C++) that gets told somehow when the Entities’ “turn” is happened, and just go through all the Entities for them to figure out their turn action.

Game dev is hard not because any given thing is “hard”, but that for every sometimes inconsequential decision there are 20-30 downstream decisions that fall right in your lap; you can look up “game development door problem” for a demonstration (sometimes it goes by “stairs problem”, or “ladder problem”) it sounds easy, and the individual thing is not super complex, but it is all the moving pieces; we end up Building the train tracks, the train, and the destination all at once and we call it a “game”. Just don’t get distracted by this cool thing you saw in some other game, or someone asked you to add, finish what you have planned then figure out if you even should add it, otherwise you might end up like Duke Nukem Forever (14 years later, and not even finished when it was released)

every project has its complexities, just break it down into smaller chunks, yes that 1 thing is now 20-30, but they are 30 smaller things that should be a lot more manageable.

1 Like

This is an extremely detailed response and one I don’t believe I deserve at this point, so thank you. My game world is a small 3D setup with the player sitting in a room in the center. The target points sit in each room and the hallways. And there is currently only one enemy AI and they will teleport from point to point. I am using target points as the teleport points so I know where they all are easily.

Thinking about what you said now, the method for me may be to just use a tracing method (is it, line-tracing?) to track where the player is, then calculate the distance of each target which it would, perhaps, call from an array, then generate the random chance roll for a movement opportunity. So it seems I would have a few different things to manage, as you said is what happens.

That’s why I made an outline document and kept the project extremely small in scale. I only started using unreal earlier this year and it was the first time I started developing in any serious capacity, so even this otherwise small thing has been taking more time than it would have otherwise. I did not learn or do anything with unreal engine in school, and everything I’ve learned has been self taught or searched online, and I feel as though I’ve been badgering the forums with my inquiries, but they have been an absolute life saver.

in Unreal Traces comes in 2 flavors, and 3 categories (technically 4), with 4 shape types (unless you define your own shape type, but that requires doing a fair bit of work in C++)
the 3 major shape types is Line, Sphere, Box, and capsule (the pill like structure around most all Pawns and characters). for lineTrace imagine you are taking a 1 particle width arrow, and flinging it through the air from the Start to the End. a Sphere, Box and Capsule Trace each of the corresponding shape same but builds a collider of that type first and instantaneously flings that shape along the line.
the 3 catagories are “channel”, “Object”, and “Profile”:

  • profile: treats the object being traced as part of that profile. in my mind this is utilized too little, as it gets the most shortcuts.
  • Channel: tests to see if anything on the given channel is in the way of the traced shape, this method can use some shorthand because the channels are defined in the profiles, but it still needs to test most objects, because for example things not being in the Visible channel is rare.
  • Object: tests each thing that the shape might collide with, and checks to see if it is of the provided type, say I wanted the First StaticMesh that is in the way of the Trace shape, but it could have any profile, or respond to any channel. This is technically the most expensive version because the collision system has to test ever object along the path.
  • Component: this is testing for that specific component type, and is often way to specific to be useful, and it is doubly hurtful because it uses string compares.

the biggest choice is Multi vs Single (the one without multi is single in Blueprints, but has the Single in C++), effectively do I want everything up to and including the blocking hit, or just the first thing the object interacts with.

the best is to search for “[shape] trace” the top 6 results will be the multi and single of each type.

when to use what shape is mostly determined by use case:

  • Box: this has some of the least use because you have to orient the box, and it just gets to be a hassle, when the box is axis aligned it is in theory just a fast as the sphere trace, but as soon as you give it a different orientation it slows down drastically.
  • Sphere: this is the second most common suggestion, because it just needs a radius, start, and end point, often times for “what is around the given object” (especially if the Start and End just so happen to be the “same” ), or manual projectile things
  • Line: this is the most common suggestion, because it just needs a Start and End, and is effectively “is there anything in the way” of say line of sight, but it is a single particle in size, so can easily miss things that are just a little bit to a side.
  • Capsule: this is probably underutilized in blueprint, because it is a quick test for “does it fit”, or “will I be blocked”, the only drawback in Blueprints in you can’t orient the Capsule, so it is only for UpVector==+Z

presuming that you are using a default UpVector=+Z, and you will be testing from the Center point of the Actor to the center point of a fixed GridSpace then a LineTrace Single by Channel should do fine, or by profile will do fine. if you are getting too many false negatives then you might need to elevate to a CapsuleTrace, but be aware you could get false positives with like Ramps or overhangs.


asking questions is more or less fine, as long it doesn’t feel like “I have no idea what I am doing can someone make my project for me”.

1 Like

Disclaimer: I am doing this project purely with blueprints. Not for lack of willingness to use C++ but it’s just… what I ended up going with this time.

So this is an aerial view of my map. The player is located in the center, in the same room as the transform cursor. Right now I have a single target point in each side room and at each doorway in the center room to keep it simple. My map layout is simple, small, and flat, so keeping track of the target points isn’t a problem, but since there are multiple rooms and surfaces that would be obscuring the line of sight of the enemy between points and the player, and I could be wrong about this, it seems like sphere tracing might be the way to go here.

This turned out to be far easier than I thought it would be in terms of finding out how to reference target points and make the “dice roll” mechanic. I just needed to put a random integer node on an if statement and build from there. I’ll probably find other small tutorials on how to add modifiers to the gameplay like stalling the enemy by looking at them through the camera, so I’ll mark this as resolved.

Your posts also gave me a lot to think about going forward. Thank you.