FollowCharacter

Started by Kinoko, Wed 15/02/2006 11:59:22

Previous topic - Next topic

Kinoko

I need a character to follow behind my player character, but no matter what settings I try, it won't follow the way I want using FollowCharacter.

I want the second character to follow the player VERY closely (ie. Walking right behind him at all times) but I can't use FOLLOW_EXACTLY or they actually stick to the player without turning or anything.

If I pass both parameters as 1, the character still doesn't follow as close as I need, and does a zig-zag as they follow the player, instead of just actually following them.

Are they supposed to do this?

Bernie

#1
Yes, FOLLOW_EXACTLY makes them stick to the player. That is intentional.

I'd recommend writing your own follow code. Just compare the x and y values and have the NPCs move towards the player's x/y coordinates when they're too far away. You can also compare to the player's current direction (loop) and make the NPCs walk to a point behind the player character depending on those.

EDIT - I made a small module:

http://www.origamihero.com/files/customfollow01a.zip (~1 KB)

You can use FolEx(folchar, mainchar) to make a character tag along. There also are a few options you can set:

FolEx(folchar1, mainchar1);
(Pass -1 to deactivate)

FolExStopDist(int x,int y);
(Stopping distance)

FolExStartDist(int x,int y);
(Starting distance)

FolExTimer(int time);
(Loops to wait after moving)

FolExStopWhenClose(int yesno);
(Whether to stop if close to player if within stopping distance)

Note: Only supports 1 following character at the moment.

A�rendyll (formerly Yurina)

Do you know when there will be more characters available to follow the player in your module, Bernie?

I'm *secretly* working on an RPG (I couldn't resist!) which involves 3 main characters. In general I thought of letting those characters follow you when you are out of events, but I also thought of making them follow you "invisible", so you don't see them except in events (like in Sailor Moon AS (SNES RPG)). What's the best option, you think?
Yuna: Give me a Y!
Rikku: Give me an R!
Paine: Give me a break...
~Final Fantasy X-2

I've been

Gilbert

If they're invisible most of the time, I think you don't need to use FollowCharacter(). Just leave the room of the invisible players as -1:
cMary.ChangeRoom(-1);

When you need the characters to appear in the current room in a cutscene just use ChangeRoom() (together with coordinates) where necessary to teleport them to the current room.

A�rendyll (formerly Yurina)

I'd only use FollowCharacter when needed, I guess.

I'm thinking of using the second (invisible) way, because that's easier to script. The difference between Kinoko's RPG and mine is I plan to make it turn-based. So it doesn't really matter for me.
Yuna: Give me a Y!
Rikku: Give me an R!
Paine: Give me a break...
~Final Fantasy X-2

I've been

Bernie

I updated the module. It supports multiple characters now and following characters also appear at the player's position when changing rooms. I also added an offset value that makes characters appear behind the character they follow upon room change.

http://www.origamihero.com/files/FolEx02b.zip

I uploaded a small example game to show you (both Kinoko and Yurina) what it could look like - it shows 2 characters following the main character in a queue:

http://www.origamihero.com/files/Compiled.zip

Kinoko

I tried it out (thanks Bernie, btw!), and from looking at your game, it seems to work fine. But, I'm a little confused about how to use it... could you give me more detail?

I imported the module, then put this code:

Code: ags

    FolEx(BRYN, EGO);
    FolExStopDist(5,5);
    FolExStartDist(5,5);
    FolExStopWhenClose(1);
    FolExOffset(1);


Where I want the character to start following the player.

Anyway, when I start my game to test, right from the start every single character in my game appears in the room and follows the player.

So, I'm guessin I have to change something in the mod's script. But what? And what code do I actually use to start this in my room script?

Bernie

#7
Uh oh! Sounds like I have some sort of mistake in there. I'll look into it, shouldn't take long.

EDIT:

Okay, it should work now. However, it's not possible to make characters follow character 0 at the moment, all the others are fine. I need to work around the array bounds somehow.

http://www.origamihero.com/files/FolEx02c.zip

Also, a new option is available:
function FolExTimer(int loops)

It makes characters stop briefly before they start walking towards the player. Default is 30 loops, set it to 0 to make them follow instantly.

Note that the characters always walk exactly towards the player, the StopDist and StartDist commands define the distance needed to make the following characters walk or stop (x or y < or > distance). Try this (provided EGO isn't character 0):

(Put them in GameStart() to try it out, that messed up earlier because of some mistakes on my part. You can call the command from anywhere in your game.)

FolEx (BRYN, EGO);
FolExStopDist(10,10);
FolExStartDist(20,20);
FolExStopWhenClose(1);
FolExOffset(2); //makes the character appear 2 pixels behind the player when changing rooms. Gotta be careful to make sure he's on a walkable area in the new room.

Kinoko

Um... he is 0 ^_^; Is there any possible workaround for this?

Bernie

Yep, there is! I wrote a small fix: Call FolExPre() in GameStart() before using any of the other FolEx commands, and off you go! You only need to do this once in GameStart(), it will work without that command everywhere else.

http://www.origamihero.com/files/FolEx02d.zip

FolExPre();
FolEx (BRYN, EGO);
FolExStopDist(10,10);
FolExStartDist(20,20);
FolExStopWhenClose(1);
FolExOffset(2);

Kinoko

Okay, after a bit f playing around, I can tell you it works -almost- perfectly. For some reason, the following character stops walking about every 2 seconds, then starts again. So, in a long straight run, the following character gets further and further away every time because of continuous stopping.

Bernie

Ah, that's the follow timer, a new command I added. It makes the following character stop before starting to walk again for a short period. Do this to get rid of it:

FolExTimer(0);

It has a default value of 30 loops, that's why you need to set it to 0.

Kinoko

#12
Okay, THAT worked :D

The only thing now is that when they walk togethr, the following character tends to "jump" sometimes, kindof flashing and looking jerky.

EDIT: Actually, this only happens when they walk along a scrolling room. Otherwise, it's fine!

Bernie

Hmm... I think that problem would occur with the normal follow command, too. The thing is, you're using anti-glide mode at a high framerate, and when the characters don't start to walk at the same time, the frames most likely won't change at the same game loop. The result of that is the jerkiness you've described.

I can't think of a fix for that at the moment. I'll let you know if I can figure something out.

Kinoko

Hmm o_o That sucks. I can't think of a work around for that, and my game pretty much won't work like that... let me go do some soul searching.

BOYD1981

could you not do it the way you were originally but edit the following character's sprite so that they are surrounded by lots (like maybe 50 pixels) of transparent space? that way the character would still be stuck on the one it's following but because of the added transparency it would appear to be following behind.
here's an example of what i mean:


you'd probably want to have the same amount of space again the other side for front and back views.

Limey Lizard, Waste Wizard!
01101101011000010110010001100101001000000111100101101111011101010010000001101100011011110110111101101011

Kinoko

I kinda don't want it to look THAT stuck. ^_^ Thanks though.

Bernie's mod is actually great for a number of reasons, so I wanna stick with that. The actual following part is PERFECT. The problem from here is, as he mentioned, with the frame rate, etc...

Kinoko

Forgive me for bumping, I just wanted one more chance to see if anyone had any idea for a solution to this problem.

Bernie

I tried a few things (like setting the following char's frame to the current frame of the player) but none of them worked so far. It's not an easy thing to fix. -_-

Kinoko

Maybe it's something I can fix in other areas... would changing the framerate help? (a little extreme but... if there's nothing else I can do)

SMF spam blocked by CleanTalk