[SOLVED]Character follow another Character's only x position?

Started by tilapisha, Mon 18/04/2022 19:23:49

Previous topic - Next topic

tilapisha

I have my Mallory character (dog) follow around the player character Goby in the repeatedly_execute function. This works for the majority of the game. However, rooms 3,4 and 5 are underwater. In this case, I would like the Mallory character (dog) just swim paddle at the top of the screen. The view for walking and swim paddle can be the same.

I tried to just assign cMallory.Walk(cGoby.x, 10); in the repeatedly_execute function, but the animation flickers and doesn't stay on the correct y-axis. I assume this is because it is in the repeatedly_execute function, and I do not think it's ignoring the original follow line.

Code: ags
function repeatedly_execute()
{
  if (cMallory.Room == 3||cMallory.Room == 4||cMallory.Room == 5){
     cMallory.Walk(cGoby.x, 15);
  }
  else{
  cMallory.FollowCharacter(cGoby);
  }
}


I searched the forums, but the cases were not similar. In one case, they were trying to get an object to follow, but I need it to have its own walk cycle.

Laura Hunt

#1
The animation is flickering because you're triggering the Walk command 40 times per second and on top of that, you're re-triggering it every time cGoby updates its position.

Off the top of my head, I would try moving this to the on_mouse_click function, rather than repeatedly_execute. I don't know what template you're using, if any, but you probably have something like this in your global script:

Code: ags
else if (button == eMouseLeft)
{
  Room.ProcessClick(mouse.x, mouse.y, mouse.Mode);
}


Then try something like:

Code: ags
else if (button == eMouseLeft)
{
  Room.ProcessClick(mouse.x, mouse.y, mouse.Mode);
  if (mouse.Mode == eModeWalkto && (cMallory.Room == 3 || cMallory.Room == 4 || cMallory.Room == 5)){
     cMallory.Walk(mouse.x, 15);
  }
}


Like I said, this is off the top of my head and untested, but it's the first solution that comes to mind.

Edit: This would also need you to change your repeatedly_execute function to:

Code: ags
function repeatedly_execute()
{
  if (cMallory.Room != 3 && cMallory.Room != 4 && cMallory.Room != 5){
    cMallory.FollowCharacter(cGoby);
  }
}



eri0o

I am not sure if this works, it depends on how you made your room. But if you simply do a long rectangle on top of the room that is disconnected from the rest of the walkable areas, and when these rooms in particular load you simply teleport the dog in it (adjusting it's position), and don't do anything else, I think it may work.

tilapisha

I am only eModeInteract with the keyboard keys for movement, and so I attempted to put this code in the on_key_press function in the keyboard movement script.

Code: ags
function on_key_press(int keycode)
{
  if (lastkey > 0 || IsGamePaused() || mode != eKeyboardMovementModeTapping || !IsInterfaceEnabled() || player.on == 0)
  {
    return;
  }

  Vector* next;

  if (keycode == keymap.KeyDown)
  {
    next = direction.Down;
  }
  else if (keycode == keymap.KeyLeft)
  {
    next = direction.Left;
  }
  else if (keycode == keymap.KeyRight)
  {
    next = direction.Right;
  }
  else if (keycode == keymap.KeyUp)
  {
    next = direction.Up;
  }

  if (next == null || (next.x == move.x && next.y == move.y))
  {
    stop_moving();
  }
  else
  {
    set_direction(next);
  }

  player.WalkStraight(player.x + move.x * distance, player.y + move.y * distance, eNoBlock);
  
  if (cMallory.Room == 3 || cMallory.Room == 4 || cMallory.Room == 5){
     cMallory.Walk(player.x, 25);
  }
     
  lastkey = keycode;
}


It worked sort of, but the dog would come back down when the player was idle. Also, it broke when the player was not in the same room as Mallory the dog.

eri0o

On repeatedly execute, you can use the moving property to see if the dog is already moving, if it's not, you can then tell him to walk to where you want. If you go this path, you have to turn off the follow as the player enters the room and turn back on when in the rooms where this is needed.

https://adventuregamestudio.github.io/ags-manual/Character.html#charactermoving

SMF spam blocked by CleanTalk