walkcycle to be completed ATLEAST once.

Started by Kimbra, Sun 18/12/2011 10:48:58

Previous topic - Next topic

Kimbra

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!

Khris

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.

monkey0506

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.

Kimbra

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...

AnasAbdin

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...

Khris

Let's try something.

Put this at the very top of the global script:

Code: ags
#define HOP_DIST 20


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

Code: ags
    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:

Code: ags
// 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!

SMF spam blocked by CleanTalk