Any workaround for shaking/stuttering movement with physics behavior ??

1 favourites
  • 8 posts
From the Asset Store
Physics Block Puzzle game template for Construct 3
  • Hello,

    I'm using the physics behavior for the controls of my player. Problem is : apparently the movement speed of objects is a bit inconsistent with this behavior. As a result it makes the player shaking a little bit.

    So the consequence is that if I try to have a dynamic camera, player sprite and cursor sprite start shaking when player accumulates speed...

    I made a simple project to isolate the issue and explain it in more detail by tracking some variables concerning speed, position and distance between the player and the camera. If anyone has a workaround to this it would be extremely helpful, because I'd prefer not to have to write my own physics from scratch to fix this issue....

    Here is a link to the test project :

    drive.google.com/file/d/1YdoG86DeHfmPQeq1FjzfWAKYOPnkqvbf/view

    Here is what happens in my game :

    Subscribe to Construct videos now
  • Try turning pixel rounding off

  • It doesn't seem to fix it.... Jittering is still visible above 300 pixels/s (in both the actual game and the test project).

  • By what method are you using to position the scroll to location relative to the ship?

    Ed: sorry didn't see you linked the project, I'll check that out.

    Ed2: nm you didn't bundle addons so I can't open it.

    Try setting the scroll to position directly with the system action instead of using a helper object and see if it makes a difference.

    Or set the helper object position manually instead of pin, if you're using that.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
    • The camera helper object is just using the ScrollTo behavior.
    • Directly using "Scroll to position" in events doesn't seem to fix the jittering.

    I updated the test project so now you should be able to open it (forgot to remove an addon effect). There are 2 layouts, although the dynamic scrolling with jittering is only in the 2nd one.

    drive.google.com/file/d/1YdoG86DeHfmPQeq1FjzfWAKYOPnkqvbf/view

    Note that for some reason, the player (and cursor) shake even more in my actual game than in this test project, and I have no idea why. But the jittering can be seen in both projects if you accumulate enough speed (and in any case it's a speed a player would be able to reach in the actual game).

    (also I would update the link in the main post too but I have no idea how to edit messages, I don't think I can). Thanks for trying to help anyway 🙏

  • From your testproject all I noticed was mostly a bit of sub-pixel jittering, nothing like in the video you posted. But when I unlock the framerate it gets really bad and looks kinda like in your video. I'm just on a 60hz screen right now so maybe you have a higher hz screen and that's why it's worse?

    Anyway, this is not a problem of the physics behavior btw. The same thing happens also with the 8 direction behavior and even with custom event logic (including the camera scroll with events) I could maybe guess it has something to do with the mouse cursor? But this seems to be a deeper issue than just some quirk of the physics behavior.

    Perhaps the order in which the events go through has something to do with it, I tried reordering but to no avail. It's possibly a complex combination of setting positions. The player moves, the cursor moves, the helper moves somewhere between, then the screen scroll moves, which also kind of moves the cursor position(?) and something somewhere goes bonkers.

  • So I finally kind of managed to "fix it"...

    My screen refresh rate was 165Hz, and I need the stepping mode for the physics behavior to be set on "Fixed", otherwise it goes wacky like in the video... However, when I set stepping mode to Fixed it also looks like player is able to accelerate faster. So with this stepping mode, will physics objects go at different speed on an other machine ? (depending on its refresh rate ?)

    Speed at which the player moves relatively to the level actually matters a lot in my game. In worst case maybe I should lower my screen refresh rate to 60Hz ?

  • I can never seem to open google drive links. It always asks me to login. So I have no input on your events.

    As far as the physics stepping mode:

    Variable will be frame rate independent but according to the box2d docs a fixed timestep is better since it makes things more consistent with the simulation. Realistically a variable timestep would only affect constraints such as joints and contacts. Can’t imagine it would be bad for simply moving objects and applying forces.

    Fixed will make the simulation more consistent but defaults to a timestep of 1/60. That means if you have a faster screen refresh rate the sim will run faster.

    A solution would be to set the timestep to match the screen refresh rate. But I forget if the physics behavior even lets you change the timestep. If it doesn’t then never mind what else I have to say. That’s kind of a blocker.

    Browsers don’t provide a way to get the screen’s refresh rate but you can guess it from the frame dt. A better guess would be to average multiple frame dts, maybe over one second. Ideally you’d want the game to be running with a low cpu/gpu load when sampling the frames so there is minimal frame skipping which would throw the average off. But it should be possible to statistically figure out that bigger dts refer to skipped frames but I digress.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)