Fishy Physics when in the Background
by Seth Willits · in Torque Game Builder · 03/10/2005 (5:47 pm) · 13 replies
I was looking through some source code when my app was open in the background, and I noticed my character slowly start moving on his own. It doesn't happen because I'm pressing keys or anything like that, it just starts moving very slowly on its own. I think (it's hard to tell) that if the cpu usage drops enough (miniscule difference though) it causes a tiny hiccup in the balance between gravity and the character resting on the ground. I believe I'm seeing the character bounce up and down then slowly build lateral momentum. As soon as I switch T2D to the foreground though, the character comes to a stop quickly.
About the author
http://www.sethwillits.com/
#2
03/10/2005 (8:08 pm)
Here is a possible fix. http://www.garagegames.com/mg/forums/result.thread.php?qt=26837
#3
I did notice something though. As soon as I press a left/right key which stops the freaky movement, it actually, stop stops it where it won't happen again after that. It also doesn't have to be in the background for this to happen, it actually starts immediately when the app opens, though it's veeeery slow. When the frame drops any amount, it seems to be the cause of it picking up speed.
03/10/2005 (8:31 pm)
Nope. That didn't work.I did notice something though. As soon as I press a left/right key which stops the freaky movement, it actually, stop stops it where it won't happen again after that. It also doesn't have to be in the background for this to happen, it actually starts immediately when the app opens, though it's veeeery slow. When the frame drops any amount, it seems to be the cause of it picking up speed.
#4
03/10/2005 (8:34 pm)
If its running under 10 fps, the physics will not work quite right. You can adjust the mScenePhysicsLimitFPS to be a lower framerate, and it will probably fix it for now. The only issue is that the engine will run a lot more iterations per frame, and will use up a lot of CPU when its in the background. You may want to try pausing the game when users switch away from it.
#5
03/10/2005 (8:41 pm)
It's not running under 10fps. It's running at 150 and it happens. It just seems to speed up when it gets down to 30. I can't quite tell, because it also seems to get to a certain level of "badness" then stays there.
#6
03/10/2005 (8:53 pm)
Can you give me some details on how you are moving your character, making him jump, setting up the scene, material properties and so on? I have what seems to be the same sort of physics as your working quite well, with very few quirks.
#7
03/10/2005 (8:55 pm)
Yeah I know. It's making me feel like an extreme n00b! lol. Everything I try has some problem or something I don't understand. Gimme a few minutes and I'll lay it out for you...
#8
I really haven't had much time to work on this so it's got some wonkyness in some areas, but nothing that i can think of that would affect it but who knows.
Thanks
03/10/2005 (9:04 pm)
www.freaksw.com/client.zipI really haven't had much time to work on this so it's got some wonkyness in some areas, but nothing that i can think of that would affect it but who knows.
Thanks
#9
We tried our best to configure the physics system to suit all three platforms for a wide range of computers but there were a few things that I forgot to change which are causing these issues. Firstly, the physics simulation needs to run to a target FPS but ultimately has a limit FPS at which point it needs to take some drastic action to ensure the stability of the physical objects.
There was also a slight mistake that was pointed-out to me on another thread where the iteration system wasn't actually attaining a target FPS as was the original intention. This has been fixed now and can cause the problem you are seeing.
I accidentally left the iteration ceiling at 16! This means that under the limit FPS (which I believe was 40fps), the system will iterate up to 16 times which is an enormous load and makes matters much worse. This was a simple mistake by me and I have already reconfigured the system so this doesn't happen with a default of 3 iterations.
You can now set the limit and target FPS as well as the iteration ceiling. You can also set the system in free-running mode which doesn't maintain a target FPS, something which lots of people may want to do.
I think the big problem here is that we're trying to provide a system that has fairly sophisticated physics that works very well for people who are not interested. With the option of essentially turning-off the system, we've now got that but unfortunately, it wasn't in the first release.
This was one of the problems with the space-shooter; when the FPS got too low, the darn 16x iterations kicked-in an blam ... 2 fps!
I'm very sorry for the confusion this has caused but it was a priority as soon as we realised what was going on. Lots of platforms and a wide array of different spec'd computers and me making a dumb mistake and leaving the iteration @ 16. Doh!
With regards to T2D running as a background process, the underlying TGE platform goes into a sleep/processing mode so that T2D doesn't take much processing whilsts in the background. I personally don't like the feature and if enough people don't like it either, we can remove it.
- Melv.
03/11/2005 (12:51 am)
Guys,We tried our best to configure the physics system to suit all three platforms for a wide range of computers but there were a few things that I forgot to change which are causing these issues. Firstly, the physics simulation needs to run to a target FPS but ultimately has a limit FPS at which point it needs to take some drastic action to ensure the stability of the physical objects.
There was also a slight mistake that was pointed-out to me on another thread where the iteration system wasn't actually attaining a target FPS as was the original intention. This has been fixed now and can cause the problem you are seeing.
I accidentally left the iteration ceiling at 16! This means that under the limit FPS (which I believe was 40fps), the system will iterate up to 16 times which is an enormous load and makes matters much worse. This was a simple mistake by me and I have already reconfigured the system so this doesn't happen with a default of 3 iterations.
You can now set the limit and target FPS as well as the iteration ceiling. You can also set the system in free-running mode which doesn't maintain a target FPS, something which lots of people may want to do.
I think the big problem here is that we're trying to provide a system that has fairly sophisticated physics that works very well for people who are not interested. With the option of essentially turning-off the system, we've now got that but unfortunately, it wasn't in the first release.
This was one of the problems with the space-shooter; when the FPS got too low, the darn 16x iterations kicked-in an blam ... 2 fps!
I'm very sorry for the confusion this has caused but it was a priority as soon as we realised what was going on. Lots of platforms and a wide array of different spec'd computers and me making a dumb mistake and leaving the iteration @ 16. Doh!
With regards to T2D running as a background process, the underlying TGE platform goes into a sleep/processing mode so that T2D doesn't take much processing whilsts in the background. I personally don't like the feature and if enough people don't like it either, we can remove it.
- Melv.
#10
- Melv.
03/11/2005 (1:01 am)
Also, I'm sorry that we didn't ship with more documentation on the collision/physics systems. Things will be much clearer when we do.- Melv.
#11
03/11/2005 (6:26 am)
@Melv: Thanks for the post, but it in the middle of the thread I pointed out that Ray's fix didn't help and that it doesn't have to happen while in the background. So it seems to me that it's something else.
#12
The other change I would try is applying the physics fix. That should stop the player from jumping really high, when combined with the previous fix.
I didn't get to actually try it out, because I am at work. Going by the sprites, It could be a lot of fun :). Let me know the two changes help at all.
03/11/2005 (7:20 am)
I looked at the code Seth, and I have a few things you can try. First try setting the player restitution for the playerMaterial to 0. This should stop the player from bouncing up and down too much (it will still bounce a little when it runs in the background, but it shouldn't build momentum). Restitution is used to set the "bounciness" of an object.The other change I would try is applying the physics fix. That should stop the player from jumping really high, when combined with the previous fix.
I didn't get to actually try it out, because I am at work. Going by the sprites, It could be a lot of fun :). Let me know the two changes help at all.
#13
03/11/2005 (7:46 pm)
I did apply your fix and that doesn't solve the sideways motion, though the restitution set to 0 does workaround the bouncing.
Torque Owner Seth Willits