pastthepixels / InfiniteShooter

A simplistic shooter made with the Godot engine.
https://pastthepixels.itch.io/infiniteshooter
GNU General Public License v3.0
18 stars 3 forks source link

Bug: The new physics frame limit per second makes some objects a bit shaky. #19

Closed Frizy13 closed 2 years ago

Frizy13 commented 2 years ago

Describe the bug Limiting physics frames per second visually breaks some elements of the game, such as walls or the red arrow. This is most evident when the limiting is low.

To Reproduce Steps to reproduce the behavior:

  1. Launch the game.
  2. Set the physics frame limit to the minimum.
  3. Press the start button.
  4. Observe unusual behavior of some objects on the screen.

Desktop (please complete the following information):

pastthepixels commented 2 years ago

I'm not sure about the arrow, but I can definitely confirm for the walls. I don't think for walls it's an issue related to the physics frame rate though -- to get it to look like it's infinitely scrolling, it just scrolls to a certain amount and then teleports back up the screen. It's probably if anything an issue with that code, but that doesn't rule out this whole bug.

Another thing I would add is that the code for shaking the screen doesn't take into account delta -- it would fit in a related bug for FPSLimit instead of PhysicsFPS since it uses _process(), but it's also notable I guess.

I think the best way to tackle this would be to search all files for _physics_process() and then see if delta is ever used (if not then correcting it).

pastthepixels commented 2 years ago

Well, I have a very sad finding. With an AnimationPlayer or with _physics_process(), the problem with the walls shaking isn't caused by bad code! What's happening (my best guess) is that since its position is being reset to zero, and the game is being drawn faster than the walls are being animated (but only by a very small amount), it's trying to interpolate between the bottom of the screen and the top of the screen and causing the jank that we see for a split second.

I could try moving the code for moving the walls from _physics_process() to _process(), but the fix might end up having to be disabling physics interpolation.

pastthepixels commented 2 years ago

Here's some quick recordings I made with OBS and a simple AnimationPlayer setup

https://user-images.githubusercontent.com/52388215/189543113-48fd7a87-9b76-4afd-a72e-e6471bec37a7.mp4

https://user-images.githubusercontent.com/52388215/189543110-d03283ee-cbd0-40b3-9257-74a5f3a077f5.mp4

pastthepixels commented 2 years ago

NEW UPDATE: Godot actually has a feature to disable physics interpolation (disabling via the editor/Node.reset_physics_interpolation())! It doesn't work with GridMaps. (Technically it does, but the MeshLibrary that's used for the walls has rigid bodies that I can't disable the physics interpolation for.)

I just think that after all this headache the best option would be to disable physics interpolation by default and add an option in the settings menu to enable it at your own discretion. Turns out the shaking wasn't caused by what I thought (bad code), so doing this would ""fix"" everything. Again we could also disable physics interpolation for the arrow and other nodes that "teleport", but that still wouldn't fix the issue with the walls so we'd have to have the option anyway

pastthepixels commented 2 years ago

FINAL UPDATE (I promise): After a couple more fixes and some testing (and a lot of school too, now), I can finally say that the game runs smoothly without interruption on my laptop. I also made some changes to the side walls so their normal shaking prior to 0.4.2 is also fixed, and it runs really smoothly now. I'll leave this issue up for a bit just in case there's something I forgot, but I'll aim to close this and merge code from 19-fix-shakiness by sometime later this week.