Animating a Character with a limp {Solved}

Started by TD2345, Tue 13/02/2024 13:00:20

Previous topic - Next topic

TD2345

Hi,

So I've created a walk cycle for a player character who has a limp. As the character walks, the limping leg drags behind him.

The issue I'm having for the character movement is that the character should move forward with the first few frames in the cycle, then remain in position as the rest of cycle plays out and the limping leg catches up. As it is, the character keeps moving forward for the entire cycle, resulting an odd gliding look.

Is there a way to make it so the forward movement only occurs for the relevant frames and that they remain locked in position for the rest of the walk cycle?

Crimson Wizard

AGS does not have such feature built-in, so this has to be done by scripting a custom movement.

I do not have a ready code example, but my thinking is this:
- save the walk destination (x,y) in global variables, and start the walking;
- in function repeatedly_execute check if the character is walking, and which animation frame it is;
- - if character is walking, and this is a frame where character should pause, then stop walking, and run animation using Animate command (non-blocking)
- - if character is not walking, but a destination is saved, and animation has finished, then order to walk towards destination again.
- when character reaches the destination, reset the global variables (in order to avoid unnecessary walking further).


On a side note, I believe that such feature is worth planning for the future versions of the engine.

TD2345

Many thanks for your suggestion. I must apologise however, I think I've phrased it poorly in the initial post. So this is for the main player character for their normal walk in-game rather than for a set animation to be played at some point. With that in mind, is what you suggested still a potential solution? Just thought I'd check as again it's completely my fault!

Crimson Wizard

#3
Quote from: TonyD on Tue 13/02/2024 13:38:35So this is for the main player character for their normal walk in-game rather than for a set animation to be played at some point. With that in mind, is what you suggested still a potential solution?

Yes, this solution may work for any character, and for multiple simultaneous characters too (in which case you would need to make an array of variables to store the custom walking info for all of them).

EDIT:
There might be additional problems here, such as a need to stop the custom walking in case player interacted with something while character was walking etc. So this may take time to figure out and resolve all potential issues.

Khris

You can do this with animation frames only; the idea is that the character's pixels move "backward" inside the sprite while the sprite moves "forward".
This causes the character's body to appear in place while their x/y coordinate still changes according to standard movement.

Crimson Wizard

Quote from: Khris on Tue 13/02/2024 14:06:42You can do this with animation frames only; the idea is that the character's pixels move "backward" inside the sprite while the sprite moves "forward".
This causes the character's body to appear in place while their x/y coordinate still changes according to standard movement.

But how would a character sync with its position later during the next animation cycle?
I guess this would require to also make the image move "forward" faster than the movement during the first phase?
But then I also wonder whether there will be a jump if character stops anytime.

Khris

#6
The limp stopping mid-animation is always an issue but pretty much unavoidable unless you code completely custom walking.

Here's a very quick example of a limping walk-cycle:


Snarky

Quote from: TonyD on Tue 13/02/2024 13:00:20As it is, the character keeps moving forward for the entire cycle, resulting an odd gliding look.

Is there a way to make it so the forward movement only occurs for the relevant frames and that they remain locked in position for the rest of the walk cycle?

You may already have done this, but the first thing you need to do is to turn the "Movement linked to animation" option on in your game settings. Otherwise the character will move some pixels each game update even when the animation doesn't update, which will cause it to glide. Once you've done that, you can use Khris's solution to vary the forward speed over the animation loop and achieve a limping effect.

Rik_Vargard

I have a character walking with a little limb and what I do is, when creating the views, at the moment that limp should be there, I just add the next frame as the same image, see?
So if your character has to "be stuck" for a short time while walking; just use/repeat the same image in the next frame(s) ...?

TD2345

Quote from: Crimson Wizard on Tue 13/02/2024 13:18:53AGS does not have such feature built-in, so this has to be done by scripting a custom movement.

I do not have a ready code example, but my thinking is this:
- save the walk destination (x,y) in global variables, and start the walking;
- in function repeatedly_execute check if the character is walking, and which animation frame it is;
- - if character is walking, and this is a frame where character should pause, then stop walking, and run animation using Animate command (non-blocking)
- - if character is not walking, but a destination is saved, and animation has finished, then order to walk towards destination again.
- when character reaches the destination, reset the global variables (in order to avoid unnecessary walking further).


On a side note, I believe that such feature is worth planning for the future versions of the engine.


This is going to be a bit of a noddy question, but I've not really touched the global variables part of the engine yet, what would be the type & initial value? I'm guessing type is a string and the value is the x,y?

Quote from: Khris on Tue 13/02/2024 14:37:29The limp stopping mid-animation is always an issue but pretty much unavoidable unless you code completely custom walking.

Here's a very quick example of a limping walk-cycle:



Would it be possible to share the code used for that example? I'm trying put together how this all works but I'm not quite connecting it together yet in terms of how I do likewise.

Khris

Like I said, I didn't use any code but simply moved the body off center in the animation sprites.

Here's the sprite sheet:

(20x20x8)

If you open this and turn on a 10x10 grid, you can see how the body moves back and forth.

Crimson Wizard

Quote from: TonyD on Tue 13/02/2024 22:31:10This is going to be a bit of a noddy question, but I've not really touched the global variables part of the engine yet, what would be the type & initial value? I'm guessing type is a string and the value is the x,y?

Better try using Khris's variant first. I might have had a wrong idea about what kind of behavior is required, and the solution that i proposed may be overcomplicated for your case.

TD2345

#12
Thanks Khris, I made a similar change in my animation cycle and it worked a charm. Thanks to everybody else who answered too.

Just for anybody else in the future looking for similar guidance, what I done to achieve the effect was crop down each frame that was part of the animation to ensure that it was essentially "tight" e.g the width of the frame was as close as possible to the character's body which as Khris explained essentially prevents any further movement and stops that floating look. I also changed up the frames, doubling up the frames for the step in the view. The extra frame made the step look better and helped emphasise the drag motion on the other leg. Furthermore, turning down the movementspeed in the options for the character and bringing it down to a level I liked to help emphasise that it's a slow limp.


cat

Just make sure that the walking speed isn't too slow, otherwise it will become annoying to players when they have to walk a lot between different places.

Khris

#14
@TonyD I feel bad for pointing this out now but your last post contains a bunch of somewhat questionable advice :P

Cropping down a frame sprite does absolutely nothing except potentially move the center of the sprite to the left or right. This could (and usually will) completely mess up the alignment of your frames because AGS uses the bottom midpoint of the sprite as the pivot to animate characters. It has no benefit whatsoever except for saying a few bytes of resource space.
It is possible that this accidentally helped with making the limp look better but that's purely coincidence.

Doubling a frame is nonsense, not just from the POV of animating something but also because you can simply turn up the delay for individual frames. In a walkcycle, using the same frame twice in a row simply means that AGS will move the character without animating it. This, again, might "improve" the look of the animation by accident but is in no way a useful thing to do in general.

Finally, the "MovementSpeed" is actually the number of pixels that the character moves in between frame changes. Ideally it should be precisely matched to the animation frames and never changed again to avoid any gliding or moonwalking.
To increase or decrease the actual speed of the character you're supposed to use the AnimationDelay property, which will make the character go slower or faster without introducing a mismatch between the character's feet and the ground.
If you look at the blue foot in my example gif, you can see that it touches the ground and remains exactly in place; this is because the foot moves to the left by 4 pixels each frame and consequently the MovementSpeed was set to 4.

Again, sorry for shitting all over your advice :P  :-[

Danvzare

Quote from: Khris on Wed 14/02/2024 14:05:49In a walkcycle, using the same frame twice in a row simply means that AGS will move the character without animating it.

Quote from: Khris on Wed 14/02/2024 14:05:49Finally, the "MovementSpeed" is actually the number of pixels that the character moves in between frame changes.
It's worth adding, that these statements only apply when you have MovementSpeedLinkedToAnimation set to true. Which is something that's on by default because it helps to avoid gliding and moonwalking in exchange for jerky movement (which for me, induces motion-sickness when walking in scrolling rooms).

If you're wanting a character with a limp, I'd highly recommend keeping that option set to true and following Khris's advice.

SMF spam blocked by CleanTalk