New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Walk animation keeps going after character arrived at destination #935
Comments
Not sure if it's the same issue, but there's a confirmed bug when on-going animation may reset to frame 0 and play again as soon as character stops: #1123 |
By the way, I did a fix where a character was stuck in either a "walking" state or "between" states for a short while, before going idle. I wonder if this is related somehow: |
@AlanDrake do you know if we are allowed to attach the test game from Franscisco, the one that you sent to me, as a test case which reproduces 100%? I wonder if it will still reproduce if we replace game gfx with placeholders, as this likely is not related to sprites. |
I don't remember, but I guess placeholders should work, only thing I'm not sure is if the number of frames have an effect over this bug. |
I mean, if it's for others to have you can put on a filesharing and just pass to the others on Discord to test, we aren't that many. |
This is for the record, because there has to be a reproducible test case in the ticket. |
So, testing this under debugger, what happens in the code is this. The algorithm in question is Line 64 in f4bd80d
Specifically, what happens when the character finished walking along one axis, but did not finish walking along another axis. For instance, it reached X destination, but not Y: Lines 73 to 81 in f4bd80d
Then the engine does the following:
By the way, notice there are 2 overriding comments in the linked code above. First CJ wanted character to "jump" to destination, but instead decided to "move" destination instead. Now, there are few nuances in this:
This makes the process longer, and this visible effect happens. The reason for the coordinate mismatch is likely a relatively low precision of fixed-point values, compared to e.g. floats. |
So, my guess is that there are 2 solutions:
In regards to p1, knowing history of AGS, there's a above-zero chance some old game was scripted to detect character at very particular positions... |
For p2: for example, adding following code in this function reduces the "walking on the same spot" considerably:
But this will also make character end up slightly further from destination. 6 pixels diff in the case of Francisco's test game, but I guess this is not overly critical for a high-resolution game. |
Well, p1 is already done, so it could be backported to 3.6 I guess. |
The small fix posted above solves the issue. Besides that, it was interesting to examine this code, as it contains old variants of logic in comments. I think it's worth to take it out and make a combined "history of changes" above the function, for convenience. Specifically noticed this piece of code: Lines 132 to 136 in f4bd80d
I immediately remembered this ticket: #663 may be worth checking that out too. |
I've been thinking about porting floats, and then I recalled there already had been a backwards compatibility issue when we replaced a pathfinder. Which means that maybe it's best to stick with the existing math in the compat. branch. |
In terms of possible move corrections, there are 2 approaches: 1) accept that the final destination is inaccurate and just stop where we are; or 2) walk part or all of the remaining destination along 1 axis. In other words: correctness vs making it "look nicer". I came to another fix idea, which hopefully will be compatible. Since the problem is that the speed along that other axis is not big enough, my idea is to create a "extra step" state in that function, which would in that case "turn the velocity vector", so to speak, and make character move remaining distance fullspeed along the remaining axis. In terms of code, this looks roughly like this:
in other words, the current position would consist of 2 parts: the regular move part, and the "final" move part which is added only in case of this unfortunate situation (otherwise it stays zero). I noticed that in high-resolution games the behavior is almost indistinguishable from simply "jumping" to the destination, as the diff is too small relatively to the screen. However, when testing the low-res game (320x200), i found that the jump will actually be quite noticeable. While the fix I am trying here visibly looks like an extra step in a new direction. So, I would really like to know opinion on this looks visually. Here's the test game I compiled: I scripted this game to make a walks between very particular coordinates that illustrate this problem case: this is done by pressing Space button. If you think that above looks bad, I guess a remaining option would be to increase the allowed destination mistake for hi-res games. Because the 2-3 pixels of allowed diff is only suitable for the low-res. |
Ideally, if there is a path to the destination, it would be nice if the ending position is exactly the destination, because people usually script a check using equality (
Only in the specific case with pressing space I can note that the player kinda "slides in", maybe because you mentioned, but any other clicking around I didn't noticed. Btw, if this changes the final position, while it's good for newly created games, this can still impact the older ones, so if there is work to keep the old ways for old games, then maybe it's similar work than backporting the float version - supposing the float version has this magically fixed. But if it still makes the character end in the wrong position (even if it's valid), then it may be better to go the other way (and later adjust it in ags4). About the strategy of moving the destination, this can be simulated at the time the Walk command is done, so that the player Destination property has the correct value from the start. |
A bigger problem of inexact stopping would be that the end point of the walk might happen to be at the very edge of a walkable area. When an automatically scaled character“overshoots” for their last step and moves off the area, and the edge of this area would have the character at, e.g., 20 % size, then this overshooting makes the character suddenly become five times as big as it should be. When inexact walking makes the character stop outside a region instead of on the region, then the event “Steps onto” won't trigger. The player themselves would have the expectation, especially in a low-res game: “I clicked with my mouse exactly there, and so I want Ego to move exactly there instead of some pixels to the side.“ |
This is true, but I might also keep the destination fixup for the old games. The old fix and this new solution do not conflict with each other. In case of a destination fix, the "final step" will simply be shorter, or zero, depending on a case. In fact, seeing how there are different versions of the code commented around this function, it's quite plausible that someone will have to uncomment and optionally support these too, for some particular very old games. |
In regards to ags4, now when I understand all this code better, it seems all or most of these fixups are not necessary at all, and if it's true, then this whole function may be stripped to a minimal code. |
Observed by Francisco in higher resolution games, when character walks all the way from right to left in some of his rooms, with movement linked to animation, once the character has arrived at destination, the animation still goes for a few frames before stopping. Not sure if relevant but he also reported using 1:2 mask resolution. He also noted he has observed the glitch before at AGS 3.4.
The text was updated successfully, but these errors were encountered: