Camera Update/Flickering
by Graham Jans · in Torque X 2D · 05/19/2007 (11:14 pm) · 7 replies
So, my intention is to have a component which will cause the scene camera to follow the object the component is attached to. Simple enough, but there is a severe flickering problem when I do this.
I have this in my component:
This seems simple enough. I add the component to the intended object and fire it up. Sure enough, the camera follows the object around. However, basically every single frame the view seems to "stutter" and I see a flickering double image of everything in the game. It almost seems like it's drawing after the object moves, then again after the camera moves, basically causing the object to be in two different screen positions in rapid succession. Needless to say, it's annoying and painful to look at.
Thoughts?
I have this in my component:
// ... in _OnRegister() _camera = TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>( "Camera" ); // ... in ProcessTick() _camera.CenterPosition = SceneObject.Position;
This seems simple enough. I add the component to the intended object and fire it up. Sure enough, the camera follows the object around. However, basically every single frame the view seems to "stutter" and I see a flickering double image of everything in the game. It almost seems like it's drawing after the object moves, then again after the camera moves, basically causing the object to be in two different screen positions in rapid succession. Needless to say, it's annoying and painful to look at.
Thoughts?
About the author
#2
As an aside, there is this note in the TX documentation: (Templates > Introduction to Templates > A Template Example)
05/20/2007 (11:59 am)
Thanks for the reply; I tried that, no luck. I also tried removing the components from my object and adding them again in a different order (I don't really know how the system works, so if that even makes a difference), but there was no change. I tried putting the component on different objects with different behaviors, no change. I'll keep trying things...As an aside, there is this note in the TX documentation: (Templates > Introduction to Templates > A Template Example)
Quote:
T2DSceneObject fuelTankTemplate = TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>("FuelTank"); // ...Another way to find a template object, which you will see in some places in the built in starter kits, looks like this:
// unsafe way to find a template object T2DSceneObject fuelTankTemplate = (T2DSceneObject)TorqueObjectDatabase.Instance.FindObject("FuelTank");This version works, but has the downside that if the template object is found but is not of the correct type for the cast, an exception will be thrown and the game will terminate. For this reason it is advised that you use the parameterized version of FindObject instead when looking up templates (and other objects).
#3
05/20/2007 (12:23 pm)
@Graham - You may be having problems because ProcessTick runs once every "tick", not every frame. Is there a reason you aren't using the mounting system to mount the camera to the object you're trying to track?
#4
the mounting system is nice, especially for camera tracking. You should look into it more, as it may be sufficient for your needs.
05/21/2007 (5:46 am)
// in _OnRegister
_camera = (T2DSceneCamera)TorqueObjectDatabase.Instance.FindObject("Camera");
_camera.Mount(SceneObject,false)the mounting system is nice, especially for camera tracking. You should look into it more, as it may be sufficient for your needs.
#5
I hadn't been using the mounting system because I didn't want the camera to directly follow the object; there was some more complex behavior in the works. The example I gave was over simplified.
In any case, I ended up using the mounting system, but adding in the complex behavior was more work then it ought to have been. Thanks again for the help!
05/21/2007 (12:32 pm)
Thanks for the replies. :)I hadn't been using the mounting system because I didn't want the camera to directly follow the object; there was some more complex behavior in the works. The example I gave was over simplified.
In any case, I ended up using the mounting system, but adding in the complex behavior was more work then it ought to have been. Thanks again for the help!
#6
05/22/2007 (1:44 pm)
Without mounting, you may be able to cure the jitters by positioning your camera with interpolated ticks or by using fixed ticking only.
#7
As others have suggested, executing your camera positioning logic from both ProcessTick and InterpolateTick (or even just from InterpolateTick, since it's currently called on tick boundaries along with ProcessTick) should solve your flickering issue.
05/24/2007 (10:31 am)
Just to reiterate, objects' positions are interpolated automatically between ticks to make object movement more smooth. If the camera is only snapping to intermediate positions on tick boundaries you'll experience a very noticeable difference in smoothness between the camera and the objects in the scene. This will make moving objects appear to a moving camera to be jittering because they are moving relative to the camera, which is still between ticks.As others have suggested, executing your camera positioning logic from both ProcessTick and InterpolateTick (or even just from InterpolateTick, since it's currently called on tick boundaries along with ProcessTick) should solve your flickering issue.
Torque 3D Owner Will O-Reagan
Modern Intrigues
// in _OnRegister _camera = (T2DSceneCamera)TorqueObjectDatabase.Instance.FindObject("Camera"); // in ProcessTick _camera.CenterPosition = SceneObject.Position