Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Kimbra on Sun 18/12/2011 10:48:58

Title: walkcycle to be completed ATLEAST once.
Post by: Kimbra on Sun 18/12/2011 10:48:58
hiya
so let's say the walk cycle is repeated every 20 pixels. what I'd like to happen is making the walk cycle complete its animation (all frames) when the character moves <20 pixels.

i hope tis not complicated  ???

Edit: to elaborate... let's say you clicked the walk cursor a coupla pixels next to the character... he'd make a little tiny winy step... no I want the whole animation to occur once between the current and new locations of the character!
Title: Re: walkcycle to be completed ATLEAST once.
Post by: Khris on Sun 18/12/2011 14:48:30
There's no easy way to do this.

I can think of two ways to handle this; either ignore walk clicks that are too close to the player or turn them into clicks farther away.
Title: Re: walkcycle to be completed ATLEAST once.
Post by: monkey0506 on Sun 18/12/2011 22:53:47
Do you want the animation to run completely regardless if they're still moving? What I mean by that, is that if they only walk, say, 10 pixels, do you want them to stop in place after 10 pixels, but still show the rest of the frames as if they were still moving?

That would be easier than if you were trying to display every frame of the animation at least once regardless of how far they're walking, but it would, IMO look...bad.
Title: Re: walkcycle to be completed ATLEAST once.
Post by: Kimbra on Mon 19/12/2011 04:32:35
Quote from: monkey_05_06 on Sun 18/12/2011 22:53:47
Do you want the animation to run completely regardless if they're still moving? What I mean by that, is that if they only walk, say, 10 pixels, do you want them to stop in place after 10 pixels, but still show the rest of the frames as if they were still moving?

Yes please :)

Quote from: monkey_05_06 on Sun 18/12/2011 22:53:47
That would be easier than if you were trying to display every frame of the animation at least once regardless of how far they're walking, but it would, IMO look...bad.

Indeed. It would look bad if the character has legs... but it would look great with a hopping character with most of the 'hop' cycle frames having space between their legs and the floor...
Title: Re: walkcycle to be completed ATLEAST once.
Post by: AnasAbdin on Mon 19/12/2011 17:11:15
I'll -try- to stir things up with concept (no code)... if you're looking for a hopping effect (a toad-like character for instance...) you can do:

1. tile the room and allow the character to stand on a fixed position on each tile- making sure the spaces between those positions are enough for one walk cycle only... (somehow similar to the toads in Sierra's Hoyle checkers...)

2. instead of having sprites with big gaps in their bottom... you could make the 'hop' cycle in the same position in all the sprites AND (drum roll) make the toad hop by changing the z position -somehow- along the walk function itself...
Title: Re: walkcycle to be completed ATLEAST once.
Post by: Khris on Mon 19/12/2011 18:09:26
Let's try something.

Put this at the very top of the global script:

#define HOP_DIST 20

Find on_mouse_click / eMouseLeft, and replace the ProcessClick line with this:

    float dx = IntToFloat((player.x - GetViewPortX()) - mouse.x);
    float dy = IntToFloat((player.y - GetViewportY()) - mouse.y);
    int dist = FloatToInt(Maths.Sqrt(dx*dx + dy*dy), eRoundNearest);
    if (mouse.Mode == eModeWalkto && dist < HOP_DIST) {
      int x = player.WalkSpeedX;
      int y = player.WalkSpeedY;
      x = (x*dist)/HOP_DIST; if (x == 0) x = 1;
      y = (y*dist)/HOP_DIST; if (y == 0) y = 1;
      player.StopMoving();
      player.SetWalkSpeed(x, y);
    }
    ProcessClick(mouse.x, mouse.y, mouse.Mode);


Basically, reduce the movement per frame depending on the distance to hop if it's below a certain threshold.

To reset the walk speed, put this above/inside repeatedly_execute:

// above
int wsx, wsy;

// inside
  if (wsx == 0) {
    wsx = player.WalkSpeedX;
    wsy = player.WalkSpeedY;
  }

  if (!player.Moving && (player.WalkSpeedX != wsx || player.WalkSpeedY != wsy)) {
    player.SetWalkSpeed(wsx, wsy);
  }


This will store the walk speed settings and restore them after the short hop.

Not tested!