Issues with walking animation

Started by WanderingWizard, Sat 08/04/2023 10:37:39

Previous topic - Next topic

WanderingWizard

Not a beginner, but this issue is making me feel like one. Sorry if there's already a post about this, but I'm also having an issue where the site won't let me search posts.

I'm having an issue where an NPC is supposed to come on the screen, introduce himself, walk toward the character, talk to him for a while, then walk away. For some reason, the walk animation doesn't play, and they glide very quickly into place. The same issue happens when I have a cutscene where the player character enters the room and is supposed to walk at their regular speed a few feet into the room and stop, but instead of walking they slide quickly to their destination. They are both standing on walkable areas.


Crimson Wizard

Are you certain that you are using Walk and not Move function?

WanderingWizard

#2
I thought I was going to be quite chagrined, but no, I am indeed using Walk.

Code: ags
player.Say("Well... here it is... let's see what's up.");
    player.Walk(124, 179, eBlock, eWalkableAreas);
    cRich.Say("Hey! Hey, mister!");
    cRich.ChangeRoom(3, 207, 198, eDirectionLeft);
    cRich.Say("Hey, I wanted to talk to you.");
    player.FaceCharacter(cRich);
    cRich.Walk(142, 179, eBlock, eWalkableAreas);
    player.Say("Oh, great.");

Here, the character is walking correctly, but not the NPC. I've checked them both with each other and they have all the same settings... and then later the player does it as well.

Crimson Wizard

Hmm, another thing that may cause this (i think) is if character was locked for animation, but then not unlocked back (LockView, UnlockView).

WanderingWizard

#4
For a second I thought that was it... I found a bit earlier where the character does an animation but I hadn't unlocked the view.

Unfortunately, it didn't fix the problem. He still doesn't animate. Somewhere along the line I changed something that makes him move at his normal speed, though. Also, the player character never gets locked and he still does the glide at one point, but that's less important because you can't see his feet in the scene. He still moves unusually quickly when he comes into view, though.

Okay, I fixed it by jumping through what I thought were some superfluous hoops, but now that I think about it I believe I understand what was wrong.

Code: ags
player.Say("Well... here it is... let's see what's up.");
    player.Walk(124, 179, eBlock, eWalkableAreas);
    cRich.Say("Hey! Hey, mister!");
    cRich.ChangeRoom(3, 207, 198, eDirectionLeft);
    cRich.Say("Hey, I wanted to talk to you.");
    player.FaceCharacter(cRich);
    --->cRich.ChangeView(16);
    cRich.UnlockView();<---
    cRich.Walk(142, 179, eBlock, eWalkableAreas);
    player.Say("Oh, great.");

I did that just to cover all my bases, but I think I was misjudging how AGS handles views. When I had him do the animation earlier, I locked the view, animated him, and later added "UnlockView," but I think he wasn't animating because he was still stuck on the other view of him shaking hands rather than his normal view, and he wasn't animating at all becauses the other animation didn't have an Up-Left loop. I supposed that "Walk" would force the walk view, but I was mistaken, and it cost me a full day of work.

That still doesn't explain why my player character isn't animating and is sliding quickly, but like I said... you can't see his feet anyway in that scene. I will take this win and be done for now.

Matti

Not sure what causes that issue, but you could try to do some debugging, like having a label that shows the player's current view, walk speed etc.

Also where is this code located, which function is it in? Is there any code before or after that snippet that might cause some conflict?

WanderingWizard

Quote from: Matti on Sat 08/04/2023 14:26:40Not sure what causes that issue, but you could try to do some debugging, like having a label that shows the player's current view, walk speed etc.

Also where is this code located, which function is it in? Is there any code before or after that snippet that might cause some conflict?

It's in the room's AfterFadeIn function, with the conditional "if (metrich > 0 && metrich <= 4)" before it. Other than that, it's the first bit of code in the room.

The only other time Rich's animations are called, it's when you first Interact with him, which runs a switch statement to see how many times you've talked to him.

Code: ags
case 0:
      player.Walk(723, cRich.y, eBlock, eWalkableAreas);
      cRich.FaceCharacter(cIan, eBlock);
      cRich.Say("Hey, there! I'm Rich.");
      cRich.LockView(20);
      cRich.Animate(0, 3, eOnce, eBlock, eForwards); 
      //(he reaches out for a handshake, but you don't respond)
      Wait(120);
      cRich.Say("Oh... okay.");
      cRich.Animate(0, 3, eOnce, eBlock, eBackwards);
      cRich.ChangeView(21);
      cRich.UnlockView();
      cRich.Say("...sorry, I guess.");
      metrich = 1;
      break;

WanderingWizard

#7
Oh, if you meant the player issue, it's in a different room's AfterFadeIn function.

Code: ags
function room_AfterFadeIn()
{
  player.Move(40, 185, eBlock, eWalkableAreas);
}

That's all there is to it. At this point, the player's animations have never been changed or touched at all.

Crimson Wizard

#8
Quote from: WanderingWizard on Sat 08/04/2023 14:55:44Oh, if you meant the player issue, it's in a different room's AfterFadeIn function.

Code: ags
function room_AfterFadeIn()
{
  player.Move(40, 185, eBlock, eWalkableAreas);
}

But Move does not run walking animation, only Walk does (unless view is locked using LockView and similar).


In regards to ChangeView, it does not unlock the view from the previous LockView, but apparently may halt current Animation, if one was running.
Code: ags
cRich.ChangeView(21);
cRich.UnlockView();
I suggest changing the order of these commands, to avoid any weirdiness. Also, if 21 is already cRich's normal view, then ChangeView call is not necessary.
Overall, character Animation should be "guarded" by LockView and UnlockView calls. LockView overrides normal view without changing it, and UnlockView releases the locked view, returning the character to its normal view.
Code: ags
cChar.LockView(N);
cChar.Animate(...);
cChar.UnlockView();
// here it will return to its normal walking view automatically

WanderingWizard

I thought the problem with Rich was going to be that I had used "Move" instead of "Walk" and just hadn't noticed it. Instead, it was the problem with the player. I can NOT believe I didn't notice that.

View 21 is Rich's "withdraw hand from spurned handshake" animation.

Also, thank you. That is the best explanation I've had of the LockView and UnlockView commands. I wasn't quite getting it from the documentation, even though it says it clear as day.

newwaveburritos

You can also use the view's name instead of a number to help you read the code.  Like:

Code: ags
cRich.LockView(VRICHHANDSHAKE);

SMF spam blocked by CleanTalk