app icon indicating copy to clipboard operation
app copied to clipboard

Fix wrong physical speed and animations jitter in low fps issues ( Make them "frame rate independent" ).

Open gonnavis opened this issue 2 years ago • 15 comments

Currently the movement speed is "frame rate dependent". If we run halfway through the block/grid scene, in 60 fps, we need 11s, in ~10 fps, we need 31s! And because of the velocity is really slowed by the low fps, the player moving more in "walking" pose instead of "running" pose.

Before this PR: 60 fps:

https://user-images.githubusercontent.com/10785634/181872586-519325dc-063c-4168-ba7d-bfdeb91147b1.mp4

Before this PR: ~10 fps:

https://user-images.githubusercontent.com/10785634/181872601-b4cf2805-3e7d-4dd4-8930-6a4d467904f2.mp4

This PR make movement speed "frame rate independent". Can see all need 13s, whether 60 or 10 fps.

After this PR: 60 fps:

https://user-images.githubusercontent.com/10785634/181872636-ce38aa48-8d8f-434a-9a8c-b31d48d7e8ca.mp4

After this PR: ~10 fps:

https://user-images.githubusercontent.com/10785634/181872645-95c7d1e3-29ce-40c0-bce8-d85ede7bf87b.mp4

But I feel it's too hard to make "additive velocity" "frame rate independent", so I directly set velocity = keysDirection in applyWasd(), instead of adding it every frame. And according to avaer's recommendation, added a dampedVelocity to control the final movement to maintain the smooth transition effect of the original version.

PS: Why 11s before but 13s now? Because of player was moving in ~1.1x speed in 60 fps before, this PR fixed this problem too, now all 1x speed no matter what fps.

Before: image

But haven't fixed the animation jitter issue in low fps yet, keep trying.

gonnavis avatar Jul 30 '22 04:07 gonnavis

Fixed "animations jitter in low fps" issue too.

https://user-images.githubusercontent.com/10785634/182003305-a29b918b-cd08-4db5-a9b5-8c48dc0090ff.mp4

gonnavis avatar Jul 30 '22 23:07 gonnavis

https://user-images.githubusercontent.com/18633264/182004175-e613a5b5-c658-4e6b-893b-84bd27e89fc0.mp4

@gonnavis velocity working good, but double jump land is messed up now, see video

lalalune avatar Jul 31 '22 00:07 lalalune

@lalalune Got it, haven't handle velocity.y yet, I'm keep doing.

gonnavis avatar Jul 31 '22 05:07 gonnavis

velocity working good, but double jump land is messed up now, see video

Fixed this problem and handled velocity.y ( fly, gravity ).

But still some "hacking" codes need turn into formal way.

gonnavis avatar Jul 31 '22 15:07 gonnavis

Haven't reviewed this yet, but I just want to say: Thank you @gonnavis for investigating this complicated bug, it was annoying a lot of people!!

avaer avatar Aug 01 '22 21:08 avaer

@alisaad673 This needs testing to check for any animation problems, in all animations basically.

avaer avatar Aug 01 '22 21:08 avaer

This Pr is causing quite a few Issues( These are i have found uptil now. I am sure there will be more. Will perform more testing on it) Issues: 1-Footsteps sound in crouch mode regressed

https://user-images.githubusercontent.com/35926530/182447672-d4d1eb37-c4c3-4c0d-ad92-f11ffb810bcb.mp4

2-In case of direct blocker in the way of avatar, this wasn't the case before:

https://user-images.githubusercontent.com/35926530/182448845-aa46ff40-92ff-42d5-9d37-b0dcb2d82857.mp4

3-The Footsteps sound randomly goes away like here:

https://user-images.githubusercontent.com/35926530/182451797-03677e94-40cf-4a19-a77b-104a9388ed9b.mp4

4-Switching to npc is broken now. and has issues: -If while running we switch to npc with 'g' key and then while the npc is running, we switch back, the npc keeps running. -If we are doing naruto run and we switch to npc, the previous vrm has weird behaviour, it gets stuck in that frame of naruto run. -In case we press E on npc after switching to npc, the screen goes blank and app is no longer accessible.

https://user-images.githubusercontent.com/35926530/182457647-b124a7a2-818a-4268-95da-0fd28af59c6f.mp4

alisaad673 avatar Aug 02 '22 19:08 alisaad673

@alisaad673 Thanks for testing, I'll try to solve them.

gonnavis avatar Aug 03 '22 00:08 gonnavis

Fixed "1-Footsteps sound in crouch mode regressed" and "3-The Footsteps sound randomly goes away like here:" issues, keep solving others.

https://user-images.githubusercontent.com/10785634/182631507-7a6ff87d-d1ab-4408-8858-e1bedea29f2f.mp4

gonnavis avatar Aug 03 '22 10:08 gonnavis

2-In case of direct blocker in the way of avatar, this wasn't the case before:

Fixed this "wrong velocity when movements blocked by obstacle" issue.

https://user-images.githubusercontent.com/10785634/182678554-fb2ad15e-ded3-49d2-bef6-7b4328f8e080.mp4

gonnavis avatar Aug 03 '22 18:08 gonnavis

Fixed "-If while running we switch to npc with 'g' key and then while the npc is running, we switch back, the npc keeps running." issue.

gonnavis avatar Aug 04 '22 01:08 gonnavis

-If we are doing naruto run and we switch to npc, the previous vrm has weird behaviour, it gets stuck in that frame of naruto run.

Hello @alisaad673 I tested that this issue already exists in master branch. ( Maybe caused by my previous PR I'll try to solve, but not caused by this PR ).

gonnavis avatar Aug 04 '22 02:08 gonnavis

Fixed "-In case we press E on npc after switching to npc, the screen goes blank and app is no longer accessible." issue.

gonnavis avatar Aug 04 '22 06:08 gonnavis

Hello @alisaad673 , I think I solved all the issues mentioned, please check and see if any more 🙏.

gonnavis avatar Aug 04 '22 06:08 gonnavis

@gonnavis This seems to be working fine now with alot of previous regressions. They seem fixed. Also its improved by a lot.

60 fps:

https://user-images.githubusercontent.com/35926530/184151693-51725791-b9a7-4138-9888-bd6c9970a61f.mp4

25-30fps:

https://user-images.githubusercontent.com/35926530/184151669-333029ec-56a0-4d30-a17d-058419c783d0.mp4

10-13fps:

https://user-images.githubusercontent.com/35926530/184151649-1b1fa994-c03c-434c-817b-ffa827126d95.mp4

alisaad673 avatar Aug 11 '22 14:08 alisaad673

Will have to revert this because it broke the idle animations.

avaer avatar Aug 13 '22 23:08 avaer

Reverted here: https://github.com/webaverse/app/commit/2c96a8dd31a9b830d7ccc79186373e036d07deee

avaer avatar Aug 13 '22 23:08 avaer