Help Creating Tile Movement System Through Arrays

Hello, I’ve looked for days to find a solution to this as well as expriment with various methods in UE4 but I couldn’t figure out how to create a good tile/grid based movement system with a first person view when I stummbled on this blog with a portion describing exactly what I was attempting to make.

I decided to spawn the meshes
dynamically at level start. Well, not
strictly dynamic since I hard coded
the boundary of the playable area.
Using the boundary data, I created an
array by dividing the total game space
grid by 100. For each of these 100x100
grids in game space, an element was
added to the array. In order to store
both X and Y coordinate data in the
array, I used two ‘For loops’ while
making the calculations. The vector
data thus obtained was added to the
array at level start, thus giving me a
list of locations that the player can
move to. As a temporary measure,
simple box meshes are spawned along
the grid at level start to depict the
grid system. The data from the grid
array is used every time the player
character is issued a move command.
Based on the click location and the
array data, I was thus able to
restrict the player movement to the
grids.

Because only a brief discription was provided I was wondering if anyone can provide some assiatance so I can create a similar blueprint to achieve a grid/tile based movement by mapping the floor of the level through an array?

is there a particular part of this explanation that your having issues with? theres many ways to do grid based systems. though trying to teach or give a general overview of how to make a grid system is a bit beyond the scope of the answerhub.

in the quoted post he he based his idea on a defined playspace that would be spawned at runtime, so not a premade level. then he spawned in a series of boxes to act as the grid itself by using nested forloops, basically one becomes the x axis and the other becomes the y. for more info on the spawning part see the procedural generation stream on the unreal engine youtube channel. he then added the locations or boxes to an array to be referenced later which provided a list of locations to move to. from there you just need to come up with your movement system which is dependent on your game. if your going for turn based kind of game then you could create a second array and populate it with all locations within your characters movement range (say 500uu). then when the player clicks the tile they want to move to you compare that tile or its location to the locations on in your array to see if its valid.

the logic is all pretty simple once you begin to understand the basic pieces. the implementation can be a little confusing if you dont have a plan though.

hello. are you trying to build an endless spawning tile just like the ones in games like subway surfers ?

No, I’m planning on making handmade dungeons but need a way to map and get the movement to be grid-like such as in Etrian Oddessy which I had issues creating and I found this method to be what I was trying to do but couldn’t find a good way to phrase it.

Thinking about it, it doesn’t need to be a single class blueprint since each map will be different but it might work better with the class blueprint for movement while it refrences the level blueprint which contains the array data to map the X and Y coordinates.

The original plan was simply restrict movement so I can build the dungeon around that instead of having to use arrays to map the level since there are easier ways to get a minimap but I ran into issues getting it to work properly as the methods I looked up didn’t seem to work or I had issues implimenting, another method I tried was making a seperate actor as a collision box and restrict movement according to it but I couldn’t figure out a way to get that working and I’m assuming it isn’t ideal for performance either.

If there is a simpler method then that would be very helpful as everything I looked up was designed around a top down strategy game and that is far from what I’m trying to build.

The idea is to have it controlled normally so it doesn’t require redoing any inputs so you can still have it operate with WASD or a controller and you move one tile at a time throughout a handmade map in first person view with seperate inputs such as Q and E for turning and with an option to move faster with another button held ala Etrian Oddessy, I’m not sure if there is a simple method to achieve this though.

if all your looking to do is control your characters movement and restrict it to a grid like system then you really dont need a grid / tile based system. all you really need to do is to have your input move the character X number of units on each press and not have it use an axis value.

at the most basic it would look like the picture below.

also ive never even heard of that game so its not a reference that really helps.

another thing to note, if your going to be trying to get your enemies to try and move in the same type of manner then it may be a bit difficult. you may end up having to write your own pathing system that uses something like A* which is a bit complex.

I had that setup but found it to be somewhat lacking since doing anything with other actors would like you said require it’s own path finding system, I was hoping the arrays and mapping out each dungeon in particular would make things simpler but it seems more complex for some quick assistance, if possible would you be able to provide some general guidance as to creating a basic one?

Apologies, if it makes more sense they wizardry is what the series is based off and that utilized a first person dungeon perspective.

That is certainly a quandry as I was hoping to be able to leverage the in-built system to at least have some rudimentary path finding even if it doesn’t really follow the player but a set path with the actor detecting the player once it’s in set path since that looks to be the most practical.

In that scenario would having a grid system be helpful or the result would be the same?

the grid would just give locations to move to, you would still need to create a movement loop for the enemy which would consist of get direction to player, get point 100uu in that direction, snap that point to grid / find location nearest to that point, move to location, delay, is enemy within range of player, if no repeat loop, if yes move on to attack script. even then it doesnt take into account obstacles such as walls or trees. without the pathing it wouldnt know the quickest route and could get stuck. you may however be able to leverage the build in navigation system for your use by getting the points of the path and working from there (see picture below).

beyond using the built in navigation, well the only choice then is creating your own pathing system which is not something ive done in blueprint as yet, though the link i posted is a good resource on pathing and the turn based strategy example on the learning page has a A* implementation in it if you can make sense of it.

you can use the inbuilt pathing / nav system as i have shown above. im not really sure what your asking for parts of your last post since its oddly worded but it seems like you want to be using the ai perception or pawn sensing given “the actor detecting the player once it’s in set path”. a sensing component will allow the enemy to see the player then begin acting how it should once the player is seen.

In that scenario would having a grid system be helpful or the result would be the same?

no idea what your asking here. in which scenario? result same as what?

maybe the following script will be of some help to you. it enables you to visualize how the built in pathing is done. basically it just draws the path between two actors, in htis case thirdperson character and a rock pillar actor. as you move your character you will see that the path is updated each time you run the script. you can combine this with the loop i mentioned earlier to pretty easily create a basic movement system like you want. then all you need to have is the grid so the enemies move between preset locations.

Apologies for the confusion, I meant the actor only walks in a circle within a small section of the map and only interacts with the player when they get in range and will return to walking around the same section again once the player is out of range, it’s for that which I’m assuming having a grid system would help to make sure the actor would only walk around it’s designated path.

if you want the enemy to walk around in a circle you just need to tell it to do so through script. how it moves from point to point in where pathing comes in. lets say you want your enemy to patrol to 4 points, all you need to do is to create an array which contains the points, then have a int variable which gets connected to a get node which returns a location from the array, use that location in a move to, then on success increment the variable and call the move to again to loop the script and move to the next location. a grid system doesnt really help in this case, you can just use world coordinates so theres no need to specify anything beforehand.

I didn’t know that, I thought it would’ve required a grid system, thanks so much for helping with my question.

Okay, I tried making creating the movement without a grid as well as have a timeline so it’s smooth and it seems to have issues as I’m unable to put anything on the map without it not working, so if possible could someone assist me in creating a simple grid system for movement?

I found an example here but the image is tiny and I’m not sure how to approach it to use for movement.

why not show what you tried and explain how it didnt work to your liking? then we could probably fix it or help to modify it to work.

as stated before a grid or tile system will just give you locations to reference which you can do via world space coordinates. so creating a system to map out world space becomes a bit redundant.

Here’s what got so far and it kinda works but I wanted to restrict it to a the center of the for example 100x100 “grid” per se as this setup doesn’t work with any boundries as it just go into geometry that has set boundries when using input axis doesn’t have, I also face some difficulty adding in reversing as I think it can be done in a cleaner fashion than made a new event.

Alongside this, I’m not sure restricting it to one actual key is a good idea as people have different layouts they use and it would be better to have it rebindable otherwise.

I’m not sure if I have to spawn invisible collision boxes at the start to make sure everything remains center as this works pretty well on an empty map but with actual things there it becomes wonky quickly.

I haven’t made one for rotation yet as I was hoping to get this working before adding +90 and -90 rotation in, thanks for taking a look at it again.

your explanation is a bit all over the place and poorly worded in places which makes it difficult to understand and respond.

your current setup should make the bp that its in move forward 500uu each time its activated. it however does not take into account any kind of collision or pathing, so you will be passing through walls and always move in a straight line. this is why before i mentioned the ai move to and the get path nodes as this will use navigation to avoid obstacles and choose the best path.

for your comment on making a “reverse” or backwards movement, well you will need another event or at least you should so its a separate input. you can however use the same script as show in your picture, you would just need to change the float value to -500. this could easily be done with a variable.

which inputs you use and the idea of rebinding inputs is beyond the scope of this question so im not really going to address that here, but you could make use of axis and action events.

I’m not sure if I have to spawn invisible collision boxes at the start to make sure everything remains center as this works pretty well on an empty map but with actual things there it becomes wonky quickly.

you didnt really explain things here so i have no idea what your talking about.

for implementing rotation its basically the same thing as you have just with a lerp rotator and a set rotation.

overall your getting there but there is inherent flaws to using a timeline as your movement as mentioned above. you may want to look into using a line trace to find obstacles and adjusting the new location accordingly.

Sorry I’ve never been good at explaining myself.

I’m not sure if I’ve done it correctly but I’m having some difficulty picturing how to connect the path point array to the lerp as I want to have it move smoothly instead of instantly.

This is what I got so far, I don’t think it’s correct though…

before we start going down this path again are you sure this is the movement style that you want? this will not be moving the character in a grid like fashion, movement on only the x and y axis is what i mean. it will allow your character to move at angles like from 0 0 0 to 100 100 0. also you may want to just use the move to nodes or regular movement in this case instead of a timeline (timelines are not terribly well performant). so suppose its safe to say that using a navigation based solution will solve some issues but may not solve all your problems.

in any event describe exactly how you would like the movement for both the player and the enemies to work. also explain a little about your game itself. im assuming its live action and not turn based, but how is the combat for instance.

in your last post you were asking about using the path points but i already showed that a few posts back. also i included some more examples below on how movement and rotation could be implemented. the movement checks for actors that you may run into via a trace. the rotation is a basic timeling lerp setup. again though tell about how you want your system and maybe we can get you an exact solution instead of just providing examples of possabilities.

Sorry, I thought I was clear when I asked the question but this is what I’m working on, it’s turn based so no live combat and you move one step per tile/grid, the minimap is segemented into squares as per each tile/grid which you can follow along as the point of view is limited to only 3-4 squares ahead of you.

I assumed I need a grid system so the player is then centered in the middle of each square as you can only move on the squares ahead of you as well as makes the minimap easier to make as it coresponds with the pre-drawn squares.

I don’t mind doing a seperate blueprint per level but I would like assistance in creating this as I couldn’t find any information on creating this in the first person view only top-down view with the player clicking on the squares to move the actors when ths is only the player moving.

I thought I explained it but I guess I wasn’t able to express it properly.