CATERPILLAR SYSTEM

A simple Caterpillar System for RM2K3 with very little code

  • calunio
  • 02/10/2010 01:01 PM
  • 22693 views
This is a code for a simple caterpillar system (event following hero) for RM2K3.

You need 4 variables:
Hero-X
Hero-Y
Event-X
Event-Y

Also, the event must be a Parallel Process.

Here is the code as it should appear on the Parallel Process page of the event:

<>Comment: First, set the position of the Hero and of the Event using your 4 variables.
<>Variable Oper: [0001:Hero-X] Set, Hero X Coord.
<>Variable Oper: [0002:Hero-Y] Set, Hero Y Coord.
<>Variable Oper: [0003:Event-X] Set, This Event X Coord.
<>Variable Oper: [0004:Event-Y] Set, This Event Y Coord.
<>Comment: Second, add this piece of code because you want the Event to be BEHIND the Hero, not in the same place.
<>Branch if Hero Up Facing
<>Variable Oper: [0002:Hero-Y] + , 1
<>
: End
<>Branch if Hero Down Facing
<>Variable Oper: [0002:Hero-Y] - , 1
<>
: End
<>Branch if Hero Left Facing
<>Variable Oper: [0002:Hero-X] + , 1
<>
: End
<>Branch if Hero Right Facing
<>Variable Oper: [0002:Hero-X] - , 1
<>
: End
<>Comment: Now, make the Event move comparing the position of the Hero and the position of the Event.
<>Comment: I also added Phasing to the event, so it won't get stuck anywhere trying to follow the hero.
<>Branch if Var [0003:Event-X] is V[0001] Less
<>Move Event: This Event, Phasing Mode ON, Move Right, Phasing Mode OFF
<>
: End
<>Branch if Var [0003:Event-X] is V[0001] Greater
<>Move Event: This Event, Phasing Mode ON, Move Left, Phasing Mode OFF
<>
: End
<>Branch if Var [0004:Event-Y] is V[0002] Less
<>Move Event: This Event, Phasing Mode ON, Move Down, Phasing Mode OFF
<>
: End
<>Branch if Var [0004:Event-Y] is V[0002] Greater
<>Move Event: This Event, Phasing Mode ON, Move Up, Phasing Mode OFF
<>
: End
<>

That's it! Pretty easy.

Also...
If you want a second event to follow the line, you can use the same code, but the second event must follow the first event, not the hero.
If you want to be able to interact with the event (like talking), use a separate parallel event to make the event move, using the code above.

Posts

Pages: first 12 next last
I've always meant to do something like this.

How do you handle things like party re-ordering in the menu? How do you determine what charsets to use in a multi-person caterpillar should the order change?
So I implemented this and it works well! I quite like the simplicity of it.

However there is one little quirk that I was wondering if you had an elegant solution for. When the Hero is up against an obstacle and faces down without moving down (or any direction), the behavior of the followers is not ideal. They will position themselves behind the Hero regardless of passibility and the fact that the hero hasn't actually moved.


Face down:


Before I start adding a ton of variables to track when a hero has changed facing without changing directions, did you have an elegant solution to this?
grrrr....no editing comments makes kentona mad!

Here is the correct image for part 2:

...and by "has changed facing without changing directions" I mean: has changed facing without changing position.
I dealt with this problem also. My personal solution was just to accept the quirk.
But now that you asked, I thought of an option (maybe not too elegant, but should work).

One simple way would be just to remove the PHASING ON/PHASING OFF from the movement code, right? That piece of code is what causes the quirk, and removing it would prevent your followers from stepping on water or passing through walls. But then, in a situations like that of the bridge, your hero would get stuck.

Solution: If you control the movement of the followers through a separate parallel event (not the followers events themselves), you can set the followers as touch events, and when the hero touches it, use conditional branches to detect hero facing, and make the hero pass through the follower, switching places. That's just a simple mechanism to remove the phasing from the code, but still prevent the hero from getting stuck.

I JUST thought of another solution, and if it works it's much simpler and more elegant: take off the phasing from the code, and set the follower events to BELOW HERO. OMG, this should work.
As for the re-ordering thing... I know a way to determine who's in your party, and set the followers' graphics accordingly. But I don't know if I could make them follow you in the order they appear on the menu. But is that really necessary?
Now, you have to make this event on every map, right?
One more thing. I got it working. My only problem is that the event has to run over to the hero from where they are in the map. Is there a way to fix that?
Yes, make an autostart event that moves the follower(s) to the location of the hero, and then at the end of the autostart event use the Erase Event command.

So it would be like:

<> Set Var0001 = Hero X
<> Set Var0002 = Hero Y
<> Change Event Location: Follower (var0001, var0002)
<> Erase Event
I figured out how to prevent that quirky movement AND prevent you from getting blocked in a narrow path AND still have the follower(s) be 1/2 or 1/3rd transparent when walking through certain tiles (such as one the worldmap forest).

Leave the followers as Same Layer As Hero but at the start of the parallel event have a <> Move Event: This Event, Phasing Mode ON and never turn it off (remove the Phasing Mode OFF lines from the original move events). This will prevent the blocking and allow for 1/2 or 1/3 transparencies.

For the quirky movement, for the first follower you need to add a simple check to determine if the hero has changed position and only do the follower movement logic if it has.

In the autostart event I described before, add two new variables Previous_Hero_X and Previous_Hero_Y and set them to the current hero's X and Y positions.

In the follower's parallel process, add this right after the <>Variable Oper: Set, This Event Y Coord.:


<> Branch if Var [0005:Previous_Hero_X] is V[0001:Hero_X] Not
<> Switch Operation: [0001:Hero Moved] ON
<> End
<> Branch if Var [0006:Previous_Hero_Y] is V[0002:Hero_Y] Not
<> Switch Operation: [0001:Hero Moved] ON
<> End
<> Branch if Switch [0001:Hero Moved] is ON
<> Var [0005:Previous_Hero_X] Set, Var[0001:Hero_X] Value
<> Var [0006:Previous_Hero_Y] Set, Var[0002:Hero_Y] Value
...insert movement code here with all the If Left Facing, Right facing, If Var [0003:Event-X] is V[0001] Less, etc...
<> End


With that in place, the first follower will only use his move logic if the hero has actually changed position, and since the second follower follows the first and the third follower follows the second, they won't move either unless the hero does.


Oops, I missed something. (Curse you lack of Edit button!!) Right after the If Hero Moved ON branch, add a line to turn it off:


<> Branch if Switch [0001:Hero Moved] is ON
<> Switch Operation: [0001:Hero Moved] OFF
<> Var [0005:Previous_Hero_X] Set, Var[0001:Hero_X] Value
<> Var [0006:Previous_Hero_Y] Set, Var[0002:Hero_Y] Value
...etc...
Now, would that be a CE, or another event on every map?
When I use this system the follower character is too slow compared to the hero. This leads to the follower character taking routes through objects and such. This also leads to the follower lagging behind the hero. How do I fix this?
Increase the event movement speed to be the same as the hero's (Normal by default).
Would this be "Frequency up" or "movespeed up" because when I use movespeed up just once, he's way too fast. Frequency doesn't seem to have an effect.
Movement: Frequency should be set to 4:Normal.

Also, try this: http://rpgmaker.net/tutorials/256/
I put his frequency to normal:4 like you said, and put a move event that said to increase his move speed. He is still way too fast. Now he stays behind the hero, but it looks like he is continuously teleporting behind the hero

EDIT: I looked at your tutorial too, but I decided that since I only need this catepillar system for a few maps and with one follower that I would use this one.
You don't need the move event to increase his move speed. Take it out.
Pages: first 12 next last