Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

Grid-like Follow the Leader Movement


Recommended Posts

I was playing Pikmin 2 which I got this Christmas and I was fascinated by how the Pikmin will follow you in a grid-like form. I wish I had a screenshot to show this, but I couldn't find any good ones showing this. Anyways, I was wondering if anyone knew how to go about actually doing this. I don't want any examples showing how to make them simply move toward you, but instead how they follow you and form a grid after they stop moving so they're nice and organized. ( Please no snapping, but instead them moving toward that grid spot. )

Edit: The way they form their grid positions should be based off of what grid coordinate is closest to them and it shouldn't be random, but kind of like a line behind you with 3 or so rows.

Edit2: Should this be in the R&D Lab subforum? If so, I'd appreciate it if a mod moved it there.

Edit3: After some thought on this, they don't need to know which spot is closest to them. Instead if an identifier is ran through them and if somehow there was a way of having some sort of identifier for their positions was established, I could have them move over to the position that matches their identifying value.

Moved thanks to Rael. <3

Edit4: I'm getting more involved on this and I think I got a solution. I'll work on it and keep updating with results may they be good or bad. My method won't require the AGBO, but it'll be restricted to 360 movement only and as I don't feel like dealing with an extension for that at the moment, a TGF version will have to wait.

Edit5: Current engine: Download | Play

Details in third/fourth post.

Link to comment
Share on other sites

I could probably be totally wrong here, but I'm thinking assign the Pikmin or whatever with a number as you get them. The first one would be one, the next one would get the number two and so on. Say, you want to have them in rows of four. If they're number they you just make them get into order by number, like this:

1---2---3---4

5---6---7---8

9--10--11--12

When one dies or you stab it with a fork or something, simply have the last in line move to fill that fron spot. So 12 would become number 1.

whatever with a number as you get them. The first one would be one, the next one would get the number two and so on. Say, you want to have them in rows of four. If they're number they you just make them get into order by number, like this:

1---2---3---4

5---6---7---8

9--10--11----

And with a setup like that you could simply have them stay in that formation all the time like they're marching. Or if you want them to sort of go all over the place or attack the enemy closest to them, when you call them back they'll still fall into place exactly like that by "remembering their number." Kind of like a "size order" line in preschool where all the short kids go in front.

Hope that helps somewhat, although I should warn you that this is only a "theory" that makes sense. Whether it can actually work is another story.

Edit: Eh, forgot to say that you can probably use like "Global Value 'P'" or something to keep track of the buggers, as I doubt it'd be possible with a counter.

Link to comment
Share on other sites

Actually Scatta, that theory helps a lot. A global value wouldn't help me none, but I can achieve your method through using alterable values to give each Pikmin a specific value. The only problem I can see with your theory is getting it to work at a specific angle, but I believe messing around with some Sine and Cosine stuff could fix that right up.

Anyways, thanks for the suggestion; I believe it'll be quite helpful. I haven't updated in awhile as I had my comp taken away during the entire Christmas break. >_>

Edit: Ok, I experimented on it all morning after getting my ideas together. Getting the grid positions set up was a complete success. My only problem was getting the follower's movement to work correctly. For some reason, telling it to go to the grid spot that matched it's identification value failed, so instead I used a loop to do this. Using the loop method, I could only make 1 event do a grid spot to follower check. Any more would harshly lower the game speed as more are created.

Anyway, here's a screenshot of what it looks like.

FTLScreenshot2.png

If anyone's interested in how I did this and would like to see how they can improve the follower movement or the engine itself, I'm releasing the source for your convienence.

Download Grid Follow-the-Leader Engine

There's some comments within the events to help you understand what was done. Also, no extensions were used.

Edit2: Uploaded it as a .ccn for those who are interested in simply trying it out. It's not the best thing there is, but I'm pleased with the grid system at least.

=Play=

Edit3: I improved the follower movement to a point where I'm actually pleased with it. The jiggling has been reduced to a minimum and the chance of them creating a hole in their formation is now very unlikely. If they do have a hole, they automatically set out to fix it. Also, as you move, they follow much better now.

The download are the same links as before.

Link to comment
Share on other sites

Double posting as the above post was getting too long.

The engine was once again improved. This time the improvement allows support for multiple types of followers. It also has better commentage, more debug control, and a few fixes to the follower movement. The links are the same as before, but here they are again for the heck of it. Download | Play

Also, new screenshot. ^.^

GFTLScreenshot3.png

BTW, this engine is open-source ( just like how the idea started ) so if you have any suggestions, improvements, comments, critisism, etc., feel free to post it or PM me about it.

Edit: Remembered to give Scatta credit. <3

Also since I seem to be really into this for some strange reason, I decided to give myself some goals to complete.

-Since in Pikmin you could use the C-rod to move the pikmin around you in a line, if you hold the right mouse button down, the followers will line up to the angle from you to your mouse.

-Without holding the right mouse, the followers should gather around you in a ( hopefully circlish ) group and move as a whole.

-Holding the left mouse will pick up a follower ( obviously getting into pikmin specifics now ) and while you're holding the follower, if you click the right mouse you can cycle through the different types of followers.

-Releasing the left mouse will throw the follower to the direction of the mouse. ( This should be simple by giving the followers basic 360 movement so they can hit the target precisely. My only challenge would be making it so the speed to fling them out gets close or exactly on the target. )

-Of course this won't be left out. Make a little system where followers can gather around an object and lift it using combined strength. ( Discussion on figuring out how many are lifting would be appreciated along with how to set up routes that they move over to and follow back to the base. )

Link to comment
Share on other sites

Just a little advice on the handelling of Pikmin: I don't know if MMF2 or whatever you're using has some type of unique id system, but every Pikmin should have a unique ID (perhaps a number 1 to 100 or so, since that was the max on the game). Every time you want to reffer to/handle that particular Pikmin, you use its ID. For example, in your system, you already have a way for the Pikmin to reference their number in line, but it'd be nice if you could have their number in line reference the exact Pikmin that's in it. Each character object (since in Pikmin 2 you could have two players and Frog things could have followers), would store which and how many Pikmin are in their group; also, each movable/workable object would store which and how many Pikmin are working on them.

Each Character/Workable object would have slots for pikmin to be in and each Pikmin would have slots for what type of object and which object they are currently working on. It'd be arranged something like this (it'd be helpfull if you knew how to and were able to use arrays):

==== Character Object #01 ====
ID: 01
Pikmin slots (100): [021] .......... [empty] .......
==== ====

....

==== Coin Object #01 (needs 5 to lift, can be carried by up to 10) ====
ID: 01
Pikmin slots (10):  [013] [005] [056] [038] [002] [010] [empty] [empty] [empty] [empty]
==== ====

....

==== Pikmin # 001 ====
ID: 001
Type: Red
Associated object: None (idle)
Associated object #: 0
==== ====

==== Pikmin # 002 ====
ID: 002
Type: White
Associated object: Coin
Associated object #: 01
==== ====

....

Every pikmin would move or act based on what object they are associated and each object would assign their pikmin to be certain places around itself based on how many pikmin are working on it.

Link to comment
Share on other sites

@Kain: About the ID system, the grid movement is actually very reliant on that. MMF ( which is what I'm using ) allows you to run a command called 'Spread Value' which sets a value within each object to its order of creation.

About the slots stuff using arrays, I understand it and all, but 1) that would mean using an extension which I'm trying to avoid and 2) an array can't be built into a specific object and I don't want to have a fat array to handle all of the object stuff.

Your mention of the array stuff gives me an idea however. I don't technically need an array as each object comes equipped with 26 values you can modify. I could still do the object association events by storing the ID of the object they're trying to move or are following into a value within them. Thanks Kain, as now I believe I know how to go about it. I'll make sure to give you credit just like I did Scatta.

@Scatta: Thanks. ^.^ I'd like to thank you as well for the formation idea, as I don't think I would have gotten anywhere without it.

Link to comment
Share on other sites

Only 26 and always 26? You see, I don't get that. I'm not saying it should be like Game Maker that has about 200 variables per object and is able to have the user define any number of their own named variables for each object. But how hard could it be to make a vector (or similar data structure) of user-defined variables associated with each object? MMF's data storage and handelling capabilities seems lacking.

Anyway, sorry for going off-topic. And good luck with this very interesting project.

Link to comment
Share on other sites

@Kain: Heh, well MMF has alterable values from A to Z, which if you count is 26. I can still accomplish the idea you mentioned, but it'll just work out a bit differently to not have to use so many variables.

Also, thanks for the encouragement. =3 It's little things like that that motivate me to keep on going.

Edit: I slightly updated the follower movement so now it doesn't twitch as much when you start moving. Also, I should have mentioned this before, but you cannot play the Internet version unless you have Vitalize, which you can get here: http://download.clickteam.com/vitalize3/plugin.html

It works with multiple browsers and you can just get the one without the extensions included as my examples don't use any. Even so, it would download them automatically if it comes across one it needs anyway.

BTW, I'll probably attempt some of my goals by the end of the week. Not today though as I need to work on something else.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...