#Fixing jittering parallax effect

1 messages · Page 1 of 1 (latest)

sour star
#

Hey, so I've been following this tutorial (https://pavcreations.com/parallax-scrolling-in-pixel-perfect-2d-unity-games/) on how to create a parallax effect for my 2D pixel art game. I'd say that 90% of it is working fine--I've got a background that, depending on the intensity value I set, can look like it's moving farther away from the screen relative to the player. But there's one issue--which the tutorial seems to address but despite my attempts to follow it nothing has seemed to change--where the background jitters slightly when the player moves.

In my game, I have my Cinemachine camera be Transposed to the player's movements, and just like in the script mentioned in the tutorial, my ParallaxEffect sets its position based on the camera's position in its Update(). I'm using a pixel-perfect camera, and my parallax effect uses the clamping function mentioned in the guide that's supposed to clamp it using my base unit of 24 pixels. But even when the parallax effect's intensity is set to 1 (meaning that it perfectly follows the camera), there is a slight but noticeable stuttering effect, almost like it's struggling to catch up. This lends me to suspect that if I figure out how to sync its movements perfectly to the camera in that case, it would work for all the other intensities.

Is there something I should be doing differently here? The tutorial mentions also syncing the camera's movements using the same pixel-perfect clamping method (setting its own position on update as opposed to using Cinemachine's transposition system, this seems kinda strange to me)--and I'm going to try to take another look at that more thoroughly, but my attempts to do that haven't really changed anything. Like I said, I have a hunch this goes beyond the quirks of having a pixel-perfect game, I think I'm just doing something wrong in making sure the background can propertly follow the camera. Advice would be greatly appreciated!

In this tutorial I'm going to explain what parallax scrolling is and how we can create it in Unity for a pixel-perfect game.

#

the jittering is still very noticeable even if all of my ParallaxEffect's code is "set the background's position to that of the camera in Update()", so it definitely doesn't have anything to do with the specific formula in the tutorial that changes the rate it moves based on intensity or whatever

onyx barn
#

Do you have a video of what happens in yours? Might be easier to identify the cause if we can see what's exactly happening

sour star
#

it'll take a bit to set up but yeah, I'll try making a recording

onyx barn
#

Sure, no rush

sour star
#

@onyx barn okay, this is really odd. I must have changed something when cleaning up my code before taking this recording, but when I actually took this footage (and tested afterward), the background seemed perfectly smooth like it was supposed to be?

it was NOT like this like 2 minutes ago, the jittering effect was previously extremely noticeable

#

wait a second

#

the jittering effect seems to go away... if the Recorder window is open (I'm using the Unity Recorder feature). the issue starts happening again once I close out of it

onyx barn
#

Oh now that's interesting

sour star
#

is
is it because there's a little checkbox in the recording menu that says "cap FPS"

onyx barn
#

I wonder if it's a framerate issue

sour star
#

i don't know anything about capping the game's framerate so it may in fact be a framerate issue

onyx barn
#

What happens if you enable vsync? You can turn it on under Project Settings > Quality > Other, it's called like vsync count or something

#

I believe you can also enable it via code but yeah

sour star
#

it was already set to "every v blank", disabling it didn't appear to accomplish anything

onyx barn
#

oh interesting

sour star
#

also, bizarrely, though I think the FPS thing might be related, ticking the "cap FPS box" in the recording window didn't change anything

it just simply... is smooth when the recording menu is open, jittery otherwise

onyx barn
#

Oh... what..

#

Now I'm even more confused

sour star
#

let me see if I can describe what's happening

onyx barn
#

You said you're using Unity's built in recorder right?

sour star
#

yes

onyx barn
#

I wonder if you could capture the jitter if you record with OBS or something

#

an external app

sour star
#

i'll just try to outline how my program works right now

#

All that's in my ParallaxEffect script right now is that in Update() it sets its position equal to that of the camera object. (which is the virtual camera that follows the player)

#

well, wait a second
it appears to move smoothly if I instead set ParallaxEffect to follow the player directly instead of the camera?

obviously I don't want to do that because it would be ideal to follow the camera instead (otherwise there could be problems during cutscenes) but I guess this suggests it has something to do with the camera

onyx barn
#

You said you're using Cinemachine right

#

yes you did

#

Okay, Cinemachine by default moves the camera in LateUpdate not Update. What if you adjusted ParallaxEffect so it sets position from LateUpdate instead?

sour star
#

still jittery. I think I tried that earlier and it didn't help
according to my CinemachineBrain the "Update Method" is set to SmartUpdate, which is assume is the default. changing that to LateUpdate as well didn't appear to change anything

onyx barn
#

Oh right smart update is the default Facepalm my bad

#

Damn I was really hoping that'd be it

sour star
#

I should also mention, I have a Pixel Perfect Camera, but I'm not sure how much that actually matters here

onyx barn
#

My reasoning was that because LateUpdate runs at the end of the frame, the camera might be updating late while your parallax updates early, so there's always that 1 frame lag

onyx barn
#

It would really only be a pixel or even half pixel difference anyway, not really anything that would cause noticeable jitter

#

At least so I think

sour star
#

the tutorial I mentioned does this whole pixel clamping thing on both the parallax and camera side. i tried it out earlier and I don't think it fully worked. the current version I have in the video just sets the position without clamping anything at all

onyx barn
#

I see. It's difficult to diganose with that video though since it looks smooth there

sour star
#

gonna try a couple of other things, see if anything changes if I have it follow my Main Camera instead of the virtual camera

#

bizarrely, I think it's actually more jittery if it follows the main camera

it only jostles occasionally when moving if it's set to follow the vcam, feels more frequent when it's set to the main camera

#

strangely, I think the "open recording window trick" only works if it's set to VCam and not the main camera?

#

@onyx barn because I can actually capture it, here's what it looks like when the ParallaxEffect is set to follow the MainCamera (not my vcam). It's also done in LateUpdate, though I think the same thing happens if I write Update instead

this stuttering effect is more noticeable than the one that normally appears when VCam is targeted instead

#

i should mention, my player moves by setting its velocity in its FixedUpdate function. the interpolate variable in its Rigidbody2D is set to "None", though I've tried the others and they don't seem to fix that either

#

hmmm. i might have been mistaken earlier, I think it's still jittery if it's set to follow the player?

#

nope, my mistake, I think the player issue wasn't working on because I set the damping values differently earlier. when it's set to 0 it works perfectly

which I guess makes sense because when it was set to higher damping values, the background was maybe more smooth but everything on the foreground (including the player) looked a lot more jittery)

#

i guess I'm happy i can take solace in having this background follow SOME object without jittering. the question is why doesn't it work for the camera objects....

sour star
#

@onyx barn Alright, it's not exactly a solution, but I think I've reached a compromise.

If I put the parallax effect function within FixedUpdate instead of Update, it's still ever so slightly jittery, but it's a vast improvement compared to before. It follows Vcam very well for the most part, and when the intensity level is cranked up to higher levels so that the background appears more distant, I think it actually becomes smoother to the point it's not noticeable at all. Since that's the case when I'll actually be using the effect (and not just a background that follows the camera exactly like in troubleshooting), that's a good sign.

Though not perfect, it's close enough, and I think that this is ultimately acceptable. The fact that changing Update was enough to achieve this result suggests that further improvements might simply involve adjusting the timing slightly, so they might not be too bad even in later stages of the project. Keeping an eye on this in the future, but I'm willing to draw the line here for now. Thanks for the support when troubleshooting, and I hope I'll be able to figure this out for real someday!

onyx barn
#

That's interesting. I'm sorry I couldn't be of more help, but I do hope you find a true solution

#

I did watch the video but I cannot make heads or tails of it

sour star
#

despite not 100% solving the problem, I at least feel secure in the fact that I tried everything I could. it's probably healthier to just keep moving vs. trying to fruitlessly iron out every bizarre minor imperfection. feeling less stressed right now that I've found a solution I can confidently state is "good enough"

onyx barn
#

This is very true. You can return to it later with a fresh mind, fixating too hard on one bug forever can drive you insane

willow plaza
#

Reminds me of this thing I can't remember