How to Make Object Randomly Teleport to Fixed Points

I want an enemy to teleport to designated locations around my map, but at random. I intend to use invisible cubes as the movement points but I cannot find a comprehensive tutorial on how to actually make an AI that randomly teleports around on its own.

Which part are you not understanding exactly? like the AI decision making? The logistics of making the enemy find and move to these points?

Well I’ve never made an AI before so I wouldn’t understand either, but I am currently focused on making an enemy randomly teleport to points I designate around the map, yes.

I have found tutorials on how to spawn enemies that chase the player physically through the world but that is not what I want, specifically. At least not for this project. I want my enemy to spawn in the same place each level (I know how to do this), and then periodically teleport from one point to another based on random chance, as they try to enclose on the player’s point, which would trigger the game over condition (I also know how to do game overs).

So, it would mainly be the logistic of making the enemy move to the designated points, and at random, yes. I just cannot find any tutorials that do this specific thing for some reason.

Easiest way to do it would probably be in the level blueprint. Add the port marker actors to the level bp as an array, then have a looping timer that fires every 10s or whatevs, select a random index from the marker array, and set the enemy location.

You’d make an actor class, called like “BP_TeleportationPoint” or something. In your enemy AI controller, you’ll want to “GetActorsOfClass” of type “BP_TeleportationPoint” on begin play (Please note: this will cause bad performance at larger scale, i.e. whenever you have a lot of AI in your scene at once. If performance is a massive concern, I can provide a better, more involved solution that reduces the strain on your system). Save the output of “GetActorsOfClass” as a global array variable (I called mine “TeleportPoints”).

You’ll also want an event that triggers a teleportation (Trigger this however you want. A looping timer is a good place to start). This event finds a random integer in the range of your array. You’ll then get the TeleportationPoint at this index and use it to teleport the character to this TeleportationPoint.

1 Like

Ok…

I will assume that your teleportation points are TargetPoints already placed in the level. (This doesn’t actually matter what it is but I’ll refer to it later as “TargetPoint”.)

First you need to get your TargetPoints in an array in your EnemyPawn. How you do this is up to you. You can either:

  • Make the array public. Place the EnemyPawn in the level and drag and drop all TargetPoints manually in the array. This works because your EnemyPawn starts at the same point so you might as well just place it there in the level. Or…
  • On BeginPlay use GetAllActorsOfClass and store it in the array. More universal but all EnemyPawns will use all TargetPoints or you’ll have to figure out a way to filter only the ones you need.

Now that you have your array in the EnemyPawn it’s just a matter of starting a timer and calling your teleport event that will move tour EnemyPawn.

Something like this:

Now this is not perfect:

  • The Teleport Interval is always the same so if you want, for some reason, to change it runtime you’ll have to modify the blueprint entirely.
  • The Random node can return the same point that you are on so sometimes the EnemyPawn teleports back where it came from.
  • In theory this BP should work in multiplayer but it is better to split the server and the client logic for clarity.

I hope this gives you a good enough base to build upon.

1 Like

^ This method is what I am looking for so I will try this. Thanks

Strong I am becoming with unreal, but not that strong. But no this is going to be a singleplayer game and I am making the mechanics as simple as possible. It’s perfectly fine for me to just have a set interval range that is established by the blueprint prior to runtime.

The only mechanics I really want to establish are a chance to teleport every few seconds, and not teleporting into the player’s room until they show up at either of the doorways and aren’t locked out first. But I think I already know how I want to achieve this specific limitation.

Ah so the teleport seems to work perfectly so far. I am going to experiment and try to set up the other conditions myself though I am sure I will brickwall soon. Thanks.

And to be specific, I am:

  1. trying to get a reference to a specific target point to trigger a potential game over condition if the door they’re at isn’t closed
  2. Restrict the teleportation so the enemy can only move to adjacent locations, which I’m sure will require an index system