- Home /
Jitter/vibration on an object with constant velocity when using 2D Pixel Perfect Camera
I've got no friction on my ground tiles, the rigidbody2D is set to dynamic, continuous collision detection, no interpolation (Interpolation did not fix the problem) and its rotation is frozen on the Z axis.The character has a velocity set at the start and whenever it jumps. I'm using 2D pixel perfect package to ensure that my assets look correctly in all resolutions, as they have a small PPU of 8. For some reason, there's no jitter when the character is moving vertically, i.e. jumping, but any form of horizontal movement creates jitter. I've also noticed that there's no jitter when the camera is stationary, instead of being a child of the object, but that means it cannot follow the player. I've implemented a camera smoother to see if that would fix the issue, but there is no change. The pixel perfect component has a resolution of 384 by 216, ppu of 8 and all other options turned off as they cause even more jitter.
Here's a link to a gif which shows the jitter (The character is in motion): https://gyazo.com/c8e4847528918c970ba0bcd2bf45c67b
Camera follow is usually called from LateUpdate to ensure that all movement will have been resolved by the time the camera moves, but that background makes it hard to see what's going on.
Answer by Namey5 · Jun 24, 2019 at 02:50 PM
This would be because of the way physics updates. In order for physics events to take place in the same amount of time regardless of frame rate, the physics systems are updated in their own constant loop. The reason the character appears to jitter is because the camera updates at a different rate to the character. To fix this, you would need to create a specific camera script that follows the player within the 'FixedUpdate' function (like 'Update', but called at the same pace as the physics tick rate).
I've added this line of code: transform.position = new Vector3(target.position.x, transform.position.y, transform.position.z); to the fixed update of the camera and unlinked it from the character. The effect still persists: https://gyazo.com/18097cff9a76187e05922c0459b50069
Your answer
Follow this Question
Related Questions
Trying to get a ball to bounce realistically in 2D. 2 Answers
Help with 2D physics script 1 Answer
Drawing Pixelated Lines 0 Answers
Pixel Art with blurry outline in Game Window 1 Answer
Limit player speed (2D) 3 Answers