- Home /
Possible reasons for lacking smoothness of horizontally moving cam
Hello everyone,
I am currently a little bit helpless with my tries to smooth a certain camera-movement, which is jittery right now. The movement is horizontal along a fixed line and shows a simple 3D map made mostly of cubes and some instances of more elaborate models. After reading a little bit in other threads I tried Lerping to smooth everything out but it didn't really do the trick (maybe i used it wrong, i don't know). For starters my initial version (context: move cursor to side of monitor->cameramovement horizontally)(EDIT:sorry for the looks of the code...in the preview it looked fine and i don't know how to fix this):
tempPosition = transform.position;
if ((Input.mousePosition.x>screenWidth-activateScrollOffset)&&(tempPosition.x>rightBoundary))
{
tempPosition.x = tempPosition.x - scrollSpeed * Time.deltaTime;
transform.position = tempPosition;
}
(Just one side for reference needed, i think.)
How I tried with lerping:
if((Input.mousePosition.x>screenWidth-activateScrollOffset)&&(tempPosition.x>rightBoundary))
{
tempPosition.x = tempPosition.x - scrollSpeed * Time.deltaTime;
transform.position=Vector3.Lerp(transform.position,tempPosition,Time.deltaTime*scrollSpeed);
}
This is placed in Update(){...}. Additional information:
I think the effect is mostly visible when there are more objects on the screen which made me think it may be an issue of too complex objects but the monitoring shows a nearly constant framerate around 65 fps +/-3 and the jittering is just too high to come from this little difference i think. I'm not doing anything which would be considered "grafic-intense" for an upper middle class pc. The effect occurs for example in situations where only around 48k vertices are shown and in some places doesn't show with much more vertices on screen. According to the doc a decent pc should be able to handle several millions.
So..I would really appreciate any ideas how to improve this. Thanks in advance!
A camera should always be moved in LateUpdate. That's because at that time all other movement has finished. This can cause lag, not from the camera, but the inconsistency in movement relative to other moving objects.
It won't get any smoother than multiplying a speed with Time.deltaTime, because mathes any speed up to per second.
I shortened the code to the relevant parts.
if ((Input.mousePosition.x > screenWidth-activateScrollOffset) && (transform.position.x > rightBoundary))
{
transform.position -= scrollSpeed * Time.deltaTime;
}
Hello hexagonius, thanks for your reply! Your explanation sounds logical to me but unfortunately I still have the same effect after moving to LateUpdate. Any other things i could check on?
Remove the if statement to see if the camera auto moves smooth then. If not, the check is bogus
Your answer
Follow this Question
Related Questions
Multiplayer: jitter caused by camera? by smoothing? 2 Answers
Gradually reduce speed 1 Answer
Rigidbody 2d smooth movement problem (It's jerky) 1 Answer