Random order of teleportation into specific destinations on map.

Hi, I am trying to make my game so that when the player goes through a door they would teleport randomly to one of seven locations on the map. As the game proceeds, there will be multiple doors and each should randomly go to a destination that was not previously teleported to until all seven destinations have been traveled to (basically the order of destinations should completely random each time the game is played).

I’m completely new to UE4 and blue prints so any help would be much appreciated.

Thanks,

M.

So you would try using a “switch on int” node. Then connect a “random int in range” node to it.

Since you have 7 locations you would put the random int in range values min 0, max 6. 0 counts as one.

On the “switch on int” node you add 7 pins, 0 to 6. 0 is first location, 1 is second location, 2 is third location and so on.

Hope this help good luck.

Thank you for your reply! I just wanted to know which blueprint I would do this on? And how would you input a specific location into say 0 to 6.0?

I would use target point placed into the wanted locations, (just type “target point” into the modes tab on the right hand side of the editor), and then i think i would use the level blue print for this action you are tying to make, since this seems like a very level specific action.

select the targets and then get a reference to them in the level bp, and get their world location. Then set your pawn or character blue print (get player pawn) and set world location equal to the world location of the target point.

I think you may need to make some kind of gating mechanism to find out where you have visited already, and lock that location. You can do this with a series of bools and branches. Basically, make a bool for each location “location01”, “location02” etc, and set them false after you have visied the location assigned.

I’m not a prpgrammer, but i don’t want to open up blue print right now, so heres what i’m thinking i’m thinking:

  • onhit>>

  • switchonint>>

  • get int Randon in range

       Min== 0
       Max=="locations"
      0- 
           branch "location00 is true" 
                true:  (set world location for player pawn == worldposition target point00
                         set location00 == false)
                false: go to 1
     1- ``              branch "location01 is true" 
                true:  (set world location for player pawn == worldposition target point01
                         set location01 == false)
                false: go to 2

TBH the way I would do it would be like this.

I put the function “Set Player Location” in the players blueprint for simplicity but I would put it in the gamestate or gameinstance which then you’ll have to do a few casting. I’d also make a “structure blueprint” (google or youtube it if you don’t know) that contains the locations(vector) and if the location is already cleared(bool). Than shuffle the Location array to randomize it. Then going through the array list, check to see if that location is cleared. If so then check the next one until we find one that is not cleared or we finish the list. If the list is finished than we know that the player cleared every location and we do a new level load or whatever you are doing. But if we find a location that isn’t clear I teleport the character to the new location. Then we stop the search(break) and set AllLocationsCleared to false, which is a local variable with a default set to true. Finally at the end of the search do a branch for the AllLocationsCleared and if its true then we load new level or whatever or if its false, setup whatever variables needed for the new location.

I’m not sure what your skill level is but that is how I would do it.

Hi, thank you for your comprehensive answer, it’s been very helpful. I’m currently trying to construct a structure blueprint. I’ve added two variables (a Vector 2D with 7 elements and a Boolean). How would I make the Boolean recognize if the location has already been cleared?

You link out a set array elem to your struct. You’ll probably need to add a name or local index variable into your struct. I forgot that when you shuffle it randomized all the indexes. So you’ll need a third variable(name, or integer. I prefer integer) to identify the index. So example, the integer “0” = location 1, integer “1” = location 2, integer “2” = location 2 and so on.

So when your player passes a level you just do a set array elem. That’ll let you edit your struct during run time. But when you edit your struct you must give value to everything or it’ll change the values to blank. Just get the original values and connected through there. Good luck.