-
Notifications
You must be signed in to change notification settings - Fork 25
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
test: linearVelocity deteriorates with time steps over 0.2s #84
Conversation
Have you checked that the body doesn't fall asleep when you do such a large timestep? |
The test still fails when I set allowSleep to false. I've found with 11524c5 that the test fails when the time step is bigger than 0.2s (not including 0.2s). I tried to find and replace all |
Does this also happen on lower velocities and the same timesteps? Maybe it hits some upper velocity limit per timestep |
Good idea. I changed the velocity from 10 to 5 and the timestep error occured at 0.401 instead of 0.201 |
If you set this to something higher, does it still happen? |
forge2d/packages/forge2d/lib/src/settings.dart Lines 62 to 64 in 8e1b6bb
Looks like this Edit: Looks like we commented at the same time; changing the value to e.g. |
Since it is that one, I would just zoom in for the rendering and use lower velocities :) |
I could simply increase this value but I don't think that actually solves the problem, but just increases the maximum time step before we see unexpected behaviour (e.g. when the user minimises and then reopens the app, the time step will be several seconds). It seems like we should be multiplying |
Oh okay I'll try that |
Even when I set the zoom to |
Also my previous point about minimising and reopening the app or browser tab still stands, see this screen recording where the bullets are at almost zero velocity after returning to the tab |
That sounds very strange, are you using flame_forge2d?
You have to either pause the engine or just discard too big |
That variable is mutable, you should be able to just change it directly. |
Yep I'm using
I feel like this should be part of the physics engine, e.g. if the dt is bigger than some threshold, break it up into 0.1s increments. |
import 'package:forge2d/src/settings.dart' as physics_settings;
physics_settings.maxTranslation = Bullet.speed; This works perfectly albeit with this warning:
|
When the game is backgrounded and then resumed, the update function is called with a very large dt time step. This might cause the physics engine to hit the maximum translation per timestep, causing moving bodies to slow down to almost-zero velocities. This PR makes the game pause if the game is backgrounded. If you'd like to change this behaviour, set the pauseWhenBackgrounded flag to true (default) or false. class MyGame extends FlameGame { MyGame() { pauseWhenBackgrounded = false; } } This is currently not working on the web, see flutter/flutter#53107. You can view previous discussion about this here: flame-engine/forge2d#84.
Description
Added a (failing) test that bodies with no linear damping shouldn't slow down over time.
If you'd like me to close this PR and just make a regular bug report issue, please let me know :)
Checklist
fix:
,feat:
,docs:
etc).docs
and added dartdoc comments with///
.examples
.Breaking Change
Related Issues
adil192/ricochlime#1
Other info
`flutter doctor --verbose`