1.5 1.6 1.7 - Camera Jitter
by Benjamin L. Grauer · in Torque Game Builder · 07/16/2007 (5:59 pm) · 194 replies
When the camera is mounted to a moving sprite, the sprite and the background are trembling (when moving).
Especially visible when there's multiple parallax backgrounds. I have the sprite moving using setlinearvelocity at about 50 and the camera mounted with a force set to 0 or higher than 5, the design screen size is 100*75 on a game resolution of 1024*768. Also, it is clearly more visible with vertical sync (and vertical sync is more than necessary for high resolution). The shaking is not something constant, but it is happening very often. When it happen, it seems like the camera go in the wrong direction then catch up back for the time of 2 frames (so, the lower is the framerate, the more remarkable is the issue).
I just tried a workaround by not mounting the camera. For that, I updated the camera position at the player position in updatescene callaback, using getrenderposition to get the exact drawn sprite position... With no success, everything is still trembling a lot.
It could be many things causing it : something with drawn sprite interpolation or camera interpolation or some updating no more happening precisely on each frame. If someone could take a look at it, I would appreciate the help.
Especially visible when there's multiple parallax backgrounds. I have the sprite moving using setlinearvelocity at about 50 and the camera mounted with a force set to 0 or higher than 5, the design screen size is 100*75 on a game resolution of 1024*768. Also, it is clearly more visible with vertical sync (and vertical sync is more than necessary for high resolution). The shaking is not something constant, but it is happening very often. When it happen, it seems like the camera go in the wrong direction then catch up back for the time of 2 frames (so, the lower is the framerate, the more remarkable is the issue).
I just tried a workaround by not mounting the camera. For that, I updated the camera position at the player position in updatescene callaback, using getrenderposition to get the exact drawn sprite position... With no success, everything is still trembling a lot.
It could be many things causing it : something with drawn sprite interpolation or camera interpolation or some updating no more happening precisely on each frame. If someone could take a look at it, I would appreciate the help.
#182
And yes, these float positions come from calculating tile center positions of the rotated tilemap and are done dynamically on the real project.
05/26/2008 (7:19 am)
@Melv: Thanks for your input, I'll look into these issues and hopefully fix the problem :-)And yes, these float positions come from calculating tile center positions of the rotated tilemap and are done dynamically on the real project.
#183
Oh it was so easy when you wrote directly to video memory ... hold on, I seem to remember that was quite hard too. ;)
Melv.
05/26/2008 (7:22 am)
You're most welcome. Ironically, making stuff work like old-school games can be technically quite challenging.Oh it was so easy when you wrote directly to video memory ... hold on, I seem to remember that was quite hard too. ;)
Melv.
#184
I've made the changes you suggested and the problem is totally gone! Thanks again!
Here is a summary for anyone interested:
I've added
I've moved all the objects and positions to pixel perfect positions
and finally on the engine side I've rounded the results of the camera position calculation in t2dSceneWindow::interpolateCameraMount
as you can see on the following animated gif, the jittering is all gone!
05/26/2008 (9:16 am)
Update:I've made the changes you suggested and the problem is totally gone! Thanks again!
Here is a summary for anyone interested:
I've added
sceneWindow2D.getSceneGraph().initialise(150,256,true,true);to my project increasing the bin size to compensate for my larger than default viewport size.
I've moved all the objects and positions to pixel perfect positions
%tileMap.setPosition(0,0);
createWallAtPos(1,0,-440); createWallAtPos(3,-44,-396); createWallAtPos(3,-88,-352); createWallAtPos(3,-132,-308); createWallAtPos(3,-176,-264); createWallAtPos(3,-220,-220); createWallAtPos(4,-176,-176); createWallAtPos(4,-132,-132); createWallAtPos(4,-88,-88); createWallAtPos(4,-44,-44); createWallAtPos(4,44,-396); createWallAtPos(4,88,-352); createWallAtPos(4,132,-308); createWallAtPos(4,176,-264); createWallAtPos(4,220,-220); createWallAtPos(3,176,-176); createWallAtPos(3,132,-132); createWallAtPos(3,88,-88); createWallAtPos(3,44,-44); createWallAtPos(2,0,0); $object = createWallAtPos(0,0,0);
$position0 = "0 0"; $position1 = "132 -44";
and finally on the engine side I've rounded the results of the camera position calculation in t2dSceneWindow::interpolateCameraMount
mRound(mCameraCurrent.mCameraWindow.point.x,1); mRound(mCameraCurrent.mCameraWindow.point.y,1);
as you can see on the following animated gif, the jittering is all gone!
#186
in? I am working with a camera width/height of 1024x768 and get about 2000 bin searches. My objects are from about 48x48 up to 500x500 for large colliders but mostly around 100x100.
Executing this before loadLevel() does not seem to make sense since loadLevel seems to overwrite this setting!? Putting it in after loadLevel() resets the scenegraph. Any ideas?
Thank you.
05/27/2008 (1:59 am)
Where exactly did you put that:sceneWindow2D.getSceneGraph().initialise(150,256,true,true);
in? I am working with a camera width/height of 1024x768 and get about 2000 bin searches. My objects are from about 48x48 up to 500x500 for large colliders but mostly around 100x100.
Executing this before loadLevel() does not seem to make sense since loadLevel seems to overwrite this setting!? Putting it in after loadLevel() resets the scenegraph. Any ideas?
Thank you.
#187
Thanks
05/27/2008 (5:33 am)
In addition to that. In the intro of my game I use pretty large textures (1024x1024) and the camera zooms in and out a lot. BinSearch goes up to over 10.000. I do not need any collisions. What kind of values do I need here or can I disable the bin stuff altogether?Thanks
#188
Thanks
05/27/2008 (5:35 am)
In addition to that. In the intro of my game I use pretty large textures (1024x1024) and the camera zooms in and out a lot. BinSearch goes up to over 10.000. I do not need any collisions. What kind of values do I need here or can I disable the bin stuff altogether?Thanks
#189
but all my objects are created in script after that, so I'm not really sure where you should put it...
05/27/2008 (10:08 am)
I added it under function startGame(%level)right after
sceneWindow2D.loadLevel(%level);
but all my objects are created in script after that, so I'm not really sure where you should put it...
#190
I'd definatley recommend reading the document I wrote here that goes into lots of background detail on the container system how to get the best results from it.
With regards to using the "initialise" call; it's a real problem when used with the level-builder. The problem is that it doesn't support those values being changed and although you can make the call, as you pointed out, it clears the objects from the scene.
When I originally wrote it you could set the values via a field or set a t2dSceneGraphDatablock (you still can). I only recently noticed that the level-builder doesn't support assigning the scenegraph datablock to it!
Indeed, this weekend I made a modification to the container system so that you can make this call without it clearing the objects from the scene. It's not something you should use in the middle of gameplay as there's a definate hit in calling it but that isn't where you'd normally call it so it shouldn't be a problem.
With this change you would make the call immediatley after the level load.
I've not checked that change into the repo yet but it's something I will be doing soon.
Melv.
05/27/2008 (10:57 am)
Christian,I'd definatley recommend reading the document I wrote here that goes into lots of background detail on the container system how to get the best results from it.
With regards to using the "initialise" call; it's a real problem when used with the level-builder. The problem is that it doesn't support those values being changed and although you can make the call, as you pointed out, it clears the objects from the scene.
When I originally wrote it you could set the values via a field or set a t2dSceneGraphDatablock (you still can). I only recently noticed that the level-builder doesn't support assigning the scenegraph datablock to it!
Indeed, this weekend I made a modification to the container system so that you can make this call without it clearing the objects from the scene. It's not something you should use in the middle of gameplay as there's a definate hit in calling it but that isn't where you'd normally call it so it shouldn't be a problem.
With this change you would make the call immediatley after the level load.
I've not checked that change into the repo yet but it's something I will be doing soon.
Melv.
#191
Problem: My mounted camera was jittery as well as shadows on moving objects.
I was able to fix the mounted camera jitter by replacing setPosition with moveTo on the object the camera was mounted to.
However, the mounted shadows are still jittery.
I read through the 10 pages and I see that Melv says he fixed the issues with Jittering and Mounted Cameras/Objects. Were they included in any of the updated over the past couple years?
What could I be missing? Doing Different?
04/19/2011 (1:56 pm)
I know this topic is a bit old, but it best describes the problem I am having and even fixed half of my issue.Problem: My mounted camera was jittery as well as shadows on moving objects.
I was able to fix the mounted camera jitter by replacing setPosition with moveTo on the object the camera was mounted to.
However, the mounted shadows are still jittery.
I read through the 10 pages and I see that Melv says he fixed the issues with Jittering and Mounted Cameras/Objects. Were they included in any of the updated over the past couple years?
What could I be missing? Doing Different?
#192
By being very careful with your camera coding (a bit unlike I was back then) you can mitigate the issue a great deal.
I suppose it is because the engine has his own update ticking, not the same as the draw with vsync, so sometimes it can be out of "sync" and having duplicate identical frames drawn without knowing it (not indication in fps count or such). It's the price for collision stability.
I suppose there's some possible definitive solutions to that, but I'm not even sure if people at GG can even see the issue by themselves to begin with.
04/19/2011 (4:51 pm)
Every fix about this issue is in the last current version of T2D. If your game is taxing on particles and has lots of stuff happening a once, jittering is at risk of happening.By being very careful with your camera coding (a bit unlike I was back then) you can mitigate the issue a great deal.
I suppose it is because the engine has his own update ticking, not the same as the draw with vsync, so sometimes it can be out of "sync" and having duplicate identical frames drawn without knowing it (not indication in fps count or such). It's the price for collision stability.
I suppose there's some possible definitive solutions to that, but I'm not even sure if people at GG can even see the issue by themselves to begin with.
#193
Found my problem. I had 'use physics' unchecked on the item it was mounted to. Checking it fixed my issue.
I have integrated Box2d into my project for all my collisions and had turned off physics on everything but I am finding that physics are used for quite a bit more than just collision detection... somewhat misleading.
04/19/2011 (5:03 pm)
Thanks for the reply Benjamin. Glad to see you active years after the post.Found my problem. I had 'use physics' unchecked on the item it was mounted to. Checking it fixed my issue.
I have integrated Box2d into my project for all my collisions and had turned off physics on everything but I am finding that physics are used for quite a bit more than just collision detection... somewhat misleading.
#194
Glad to hear you resolved your camera issue.
04/19/2011 (5:46 pm)
I'm not active anymore on GG, I moved on. But I didn't deactivate mail notification on this thread xDGlad to hear you resolved your camera issue.
Employee Melv May
Straight to it: The problem is that you're asking TGB to render objects at fractional positions but you're making a world-unit equal a pixel. I presume that the reason you're setting the world-unit/pixel ratio to 1:1 is so that you can specify your artworks position in pixels. If this is so then don't be suprised when the fractional world-positions don't align with pixels when you move the camera a fractional value.
This problem can be demonstrated by the script best if you slow-down the object that's moving. It has nothing at all to do with frame-rate.
To fix this I removed the fractional values you used for your positions. If you want pixel units then I'm not sure why fractional values have been used (the 2.3e-005 seems to indicate it's pasted from somewhere?). Removing the fractional parts resolves the issue but of course you'll more than likely want to round up/down the values as appropriate.
I know you mentioned this above and you had issues with these objects in relation to the tile-map but again, that's the same problem. If you absolutely want alignment to pixels on the screen then all your objects must be aligned to pixels. Any that are fractional will shift slightly if the view moves.
If you move the camera, say with the mouse, to integer positions you'll also remove other issues like this.
It comes down to the fact that if you want to operate in pixels then you need to do everything in pixels. Moving the view fractionally can have side effects.
It is possible to restrict the view to pixels only but not from the scripts only. It's only a relative minor change in the engine.
Melv.