Holy **** I made a guy move by checking an array!

This is so entry level it’s embarrassing, but not being able to get a lego-block scripting system in another engine to do this is what originally pushed me over to UE4. I wanted to create an array of floor tiles to move a guy between, and when I asked the program if I could get some information out of the array it smiled and asked “Why would you want to do that?”

Now arrays were the math that I reached in school that finally made me commit to being an artist full time so trying to tackle them was an added aspect to this challenge. It took me about three weeks to get back to where I was in that other program. UE4 is simultaneously both more intuitive to use and more obtuse to interpret. This likely has a lot to do with me simply not understanding how it’s trying to talk to me, and just learning “where is the bathroom” has taken a lot of nights and frustrated google searches. So it’s a bit steeper in it’s opening learning curve, but once that barrier is pierced holy cow does it open up.

So I figured out to get the player shunted into a camera, then tossed in a some placeholder art. I spent a bunch of time looking at how inputs were handled and realized that my player movement has more in common with an elevator than a standard hold-a-direction-apply-velocity player character. With that break through I was finally able to get him moving on an arbitrary number using the following:

So he’s moving! But **** if it wasn’t a bitter taste because it was just any old number right? There was no accuracy to it and if I had stretched my game space out, or made any alterations to the size of the objects in question, the character would have ended up off of the center of the tiles. I needed something that I KNEW was putting him on the floor tiles exactly, and I needed those tiles to be able to communicate to me and with the wider game. I knew I needed to get back to that notion of the array but even getting this far was like pulling teeth. The breaking point was when I noticed the “Context Sensitive” check box in the node search box! Suddenly I have access to all the stuff that UE4 thought I didn’t actually want because I was prototyping everything in the Level Blueprint, even stuff that will eventually shift over to class objects. I had access!

So I find the MakeArray node, get my actors plugged in, and cant seem to find anything that will take it’s weird box pin. I eventually spot a GET node in a screen shot that seems to bridge the gap between the array pin type and the standard round pin. I do a bit of checking and learn that theres a bunch of different ways to get information out of an array using one of those styles of nodes but GET seems to be the best for the job. I make some adjustments to the variable names and make sure my array gets built during the initial game start. This is where things get tricky. I have my player’s CurrentTile position number, so with a little trepidation I plug that directly into the lower left pin for the SetArray node. Seeing as I have the Set CurrentTile variable exec’ing the TileArray I worried a bit that this would be too self referential, but I reasoned that I’m going to want them to be the same number, at least for the moment.

With that assembled there was no way (that I know of right now) to be sure it would work without actually hooking a player’s movement keys to it and seeing what would happen. So building off my old arbitrary movement script I get something that says “Ok I pressed the Right Button! Hey Player Character, is your Current Tile less than six? I don’t want you running through a wall cuz that’s stupid”
“Umm” The Player Character looks at a number written on his hand, “No it’s ok! I’m on a tile less than six!”
“Good, I want you to move to whatever your Current Tile happens to be, plus one. Here’s a list of tiles. Do you see one that matches your number?”
“Yeah here it is,” Player Character checks between the two, “So that number plus one is…” He looks at the next tile in line, “It’s that one.”
Player Character starts moving to the new tile.
“Ok while you’re doing that I want you to make sure you stay at your same height”
“Yeah I know, that’s a silly thing, but just make sure you don’t drill into the ground to try and get to that next tile. I’ll fix that when I make you a Class Blueprint of your own, probably.” I scratch my head, “I’ve gotta lock you to the x axis somehow…”
Player Character shrugs, “Ok whatever man.”
“Oh and one last thing! When you get to the new tile, I want you to write it’s number down so you don’t forget. I’ll probably be asking you to move again soon.”
“Got it!” The Player Character says as he reaches the tile. Before he stops completely he pulls his sharpie out and jots down a new number on his palm.

And all of that looks just like THIS:

Silly narratives to describe scripting aside this feels like a serious step forward with the engine. I had an idea, could think of roughly how it should be done, built it, and it WORKED. I’m so incredibly thrilled with the results I’ve had with UE4 so far and I really haven’t even gotten my feet wet. Also I have no doubt that what I’ve put together is cludgy in some terrible ways. If anyone wants to point out a better way of hooking things up I would love to learn from you. For example I can already tell that branch I have in my game start is completely superfluous. Gonna get that updated in a few minutes…

Next up is getting him to translate between two spaces and actually walk there instead of teleporting instantaneously.

This is exciting, I am excited!

I know exactly how you feel! I am completely new to UE4 as well, and the amount of success I’ve had so far is outstanding to say the least. I commend you for figuring that out on your own, but would like to know if there’s a more efficient way of doing that as well. I am building a top-down style game that this will help a lot for my thought process. I am utilizing basic AI control for my characters instead of adding the information directly into them, that way I can tell multiple different characters to do stuff without possessing them (among some other basic reasons). If this is going to be your only controllable character though, it may be unnecessary to implement that style of control.

I don’t have UE4 in front of me right now, but I think there is a BP node for character movement that you could use instead of Set Actor Location. As long as your character is a character class, then there shouldn’t be any issues with that. Since you already know your destination, you should just be able to tell the character to “move/walk/run/fly/swim/etc.” to that location. When I get home tonight, I’ll look and see if I can find what I’m talking about and post something you might be able to incorporate.

Hey there Amsirahc, and thanks for the encouragement. I was definitely on a rollercoaster high of I-Can-Do-Anything when I wrote that.

I’m in the process of working on getting the character to accept input from button presses, but you might be right. The final character movement I have in mind is less like the standard player character paradigm, and more like Q-Bert crossed with the blow trading of a fighting game, and I’m early enough in the process that I’m pretty interested in learning as many different implementations as possible.

I’ve been working with Jared Therriault to try and build a solution with a lerp, but I’ve discovered that every movement you might want would require it’s own specially tuned curve due to the system registering both the time and value of the curve when it affects the movement of the object. This weekend I’m going to try out his iTween plug in, which is supposed to make that process as simple as adding a Math Divide to the alpha to change the point to point transition speed.

You can see experimentation here: Elevator Style Character Movement

Your explanation of your script was amazing. I now want to get someone to write a book that is the explanation of how the game works just like that. lol

Hey Stinkhorse, no problem! It’s a learning experience for us all. So, here’s kind of what I was thinking…


Basically, instead of setting the absolute position of the character (as long as it’s a Character or DefaultPawn class, otherwise you’ll have to do some finagling to get it to work right), you can use a while loop to check the current location against the desired location (within a tolerance range) and tell the character to apply movement in the direction you want as input to the World Direction (in your case it should be along the -Z axis I believe). Once the character has reached the destination, you just tell it to stop movement.

Just realized that you could just drag the pin from the subtract to the World Direction pin on Add Movement Input (too lazy to re-open and re-draw this up :P) to get your desired direction as well.

Again, not 100% certain this will work for you, but it might be worth a shot for testing purposes. I’m not very far into applying animations yet, so can’t exactly say where you would want to stick that in there, but let me know if that’s the idea you were looking for.

Good luck!

EDIT: Also, you may have to associate the target with your character as well instead of the obligatory self, forgot to mention that.

Well, I’m glad you were able to get this working, I am pretty new to UE4 as well, I came from straight C++, but not even knowing how to program in being able to zoom a camera in and out, or resizing something was quite a pain, so I found this engine. I am pretty excited about the game I am making, I am making a 2D minecraft, with some 3D aspects to it. Currently I am already able to generate a random world, mine blocks, and it was all pretty easy. I plan on publishing this game and am glad I found this engine, all I can say is that this engine is great!:smiley:

Heh, thanks Hawk.
One of the troubles I was running into in the first few days when I started was how difficult it was to follow other people’s blueprints or finding comments that clearly explained how a given script or function worked in relation to the bits around that. Also I’m a conversational learner, rather than a hands on or book learner, so talking about a problem really helps. If it helps other people I’ll keep giving overly thorough run downs of the stuff I’m building.

Hey that’s sweet Amsirahc!
I’m definitely going to try this over the weekend, though I’m going to have to futz with it some, because one of my big things is avoiding hard set numbers in favor of something dynamically built wherever I can. If I decide to change anything on the art side going forward it’ll be easier to do if I don’t have to worry about updating a bunch of numbers squirreled away in a ton of blueprints. Jared Therriault walked me through a detailed function that can build a reference array of the world position numbers of another array of objects, so I could potentially use that to get an XYZ location to head toward, but instead of lerping there I’ll bring your setup into play and see what happens. I’m not animation ready either but I’d be surprised if getting something to appear on a mid move call wasn’t something relatively easy. I’m also kind of hoping that Spine is ready to go with a UE4 plugin by then, because that would be the best.

But yeah, your solution and Jared’s iTween plugin are my weekend test projects to feel out.

That’s awesome man! I think I saw your thread too. I think you sold it there as less a 2D Minecraft and more like a 3D Terraria. Rama replied to your thread didn’t he? Did you try out his Victory functions with the randomized seeding? Did it work out for you? I am officially Comrade Questions.

Afternoon Amsirahc!

I am sorry to report that the engine did not like that at all! You were right that the Stop Active Movement required a reference to the pawn, otherwise it wouldn’t compile. When it did compile it complained of endless loops, so I probably hooked it up wrong, or it didn’t like the fact that I was asking it to reference the array for it’s location to go to. I get the feeling that this should work as a solution, that is I think your idea is a good one, but I’m not sure I have the chops to figure out where I’m going wrong with it at the moment. I’m probably doing something like continually updating the starting location so the guy never figures out where he’s supposed to leave from, or something silly like that.

I’m going to put a pin it in for the moment while I try out iTween, but this movement system seems like it should be suitable for my needs. Maybe I just need to start with a simpler test…

Hmm, that’s quite possible. If you are referencing the array for your location, and not the actual actor’s location, then you would need to update the location within the loop before it checks again. Otherwise, you’ll end up with it saying something like…

WhileLoop: “Hey, where are you?”
Array: “I’m at position X,Y,Z”
WhileLoop: “Alright, let me do this stuff and I’ll check back in a few”
WhileLoop: “You still in the same place?”
Array: “Yep, haven’t changed”

Let me know how the iTween plugin goes, and ultimately which method you end up going with. There are tons of different ways to accomplish the same task in this engine, which is what makes it an amazing solution IMHO. Starting with a simpler test would be a good idea. Try taking a plain character/pawn object and performing the movement tests against it, then incorporate your other functionality after the base test succeeds.

So I just finished the first run of the iTween plugin. It works exactly like you would expect it to. You feed it a target, give it the starting point and the end location, tell it how long to take and describe the flow of the animation (ease in/out), and you’re done. The simple node still has a lot of options on it in comparison to most any other node I’ve seen, but it’s full options node is a kind of quiet comedy in terms of how extensive it is.

the solution was so dirt simple I’m genuinely curious why it’s not in the engine proper.

That’s fantastic! I’ll have to check out the iTween plugin sometime. Looks fairly simple and very useful. Best of luck on your game!

Looks like my evil plan is working!

Hey Stinkhorse!

Haha, evil plan HELLA in effect!

One heck of a good job you’ve done there Jared! I will definitely be using this in the future. Here’s to hoping they incorporate your node into the engine :slight_smile:

Thank you Amsirahc! I don’t think I’ll be submitting it as a pull request though. While the system is rewritten from the ground up for Unreal, it’s still a port of the Unity iTween plugin. I think the easing equations license alone would make that difficult. But it IS free and I’ve tried my best to make it as easy as possible to install and use, so please feel free!

No problem! That would prove to be a bit of an issue. Either way, free is good, and functional just makes it even better.