How to have a playable character follow around the active playable character?

Started by Scrungo, Thu 07/03/2024 15:40:57

Previous topic - Next topic

Scrungo

Hello, I am implementing my game to have two playable characters, which I have the character switching portion of the code working fine. But I want them to follow each other, particularly in a Hiveswap act 2 manner, (a more classic, but not as accurate to my scenario, example might be how Sam & Max: Hit the Road do it) where the non-active player follows the active player, until switched.

my code so far is this:
Code: ags
     else if (keycode == eKeyF1)
    if (player == cEgo) {
      cRoger.SetAsPlayer();
      cEgo.FollowCharacter(cRoger, 0, 20);
    }
    else if (player == cRoger){
      cEgo.SetAsPlayer();
      cRoger.FollowCharacter(cEgo, 0, 20);
    }
I have two problems:

1. They do not start to follow each other until F1 is actually pressed, which yeah, duh, its on function on_key_press, so no surprises there. I tried putting the (FollowCharacter portion of the) code into the function repeatedly_execute(), which did work, but I did not think this was code that needed to be ran repeatedly. What would be the proper way to make the character automatically start following each other when the game starts?

2. When they do follow each other, they get get a bad case of rubberbanding. As in, the active player character will move, the non-active player character will follow behind, and then the active player character in front will course correct, and move backwards to follow the non-playable character, even though they shouldnt be following them since the non-playable character should be the only one following anybody.

Any help is greatly appreciated, thank you so much for your help!!!! :D

Khris

1. You can put the code in game_start, or in the first playable room's room_Load function (i.e. the enters before fadein event).
As you've said correctly, setup code never goes into rep_exe, which is only supposed to be used when necessary.

2. Sounds like all you need is also call cEgo.FollowCharacter(null); when you set them as active player character, same for cRoger.

Scrungo

Sorry for the incredibly late reply, but thank you so much Khris, I was able to get it to work perfectly with your help!! You're the best, man!! :D

SMF spam blocked by CleanTalk