Camera Jittering

Discussion and feedback on Construct 2

Post » Fri Sep 04, 2015 2:16 pm

Hey everyone, I'm looking for some advice on removing jitter from my camera.

I'm using this tutorial https://www.scirra.com/tutorials/626/making-a-smooth-following-camera?page=2 to try and create a smooth camera effect. Which is using a scroll-to behavior with the lerp function.

However, as you can see in the gif, everything seems to be jittering quite a bit.

This happens in both Firefox and Chrome browsers.

Image

Thanks in advance for any advice.
B
9
S
1
G
2
Posts: 32
Reputation: 1,974

Post » Fri Sep 04, 2015 2:21 pm

Just off the top of my head, do you have pixel rounding on?
B
103
S
38
G
19
Posts: 962
Reputation: 17,996

Post » Fri Sep 04, 2015 4:04 pm

Ooh I remember having that problem too. The thing is that for pixel art you'll need to be careful about how much you move objects so they'll align with the limited pixel grid properly by each frame update. So if you move the camera by say, 0.6 pixels per frame update you'll get movement updates like this:

0.6 - 1.2 - 1.8 - 2.4 - 3.0 - 3.6 - 4.2 etc

which converts to these integers:

1.0 - 1.0 - 2.0 - 2.0 - 3.0 - 4.0 - 4.0 etc

In this scenario the object will move one pixel every second frame, except when it's moved 3 pixels the rounded float position will make it move right up to 4 on the next frame, causing a jerk. And that's assuming the engine keeps a steady 60 fps and the camera scrolls at an even speed. Lerp doesn't account for that kind of thing and neither does the scroll-to behaviour.

The easiest thing to do is just turn pixel rounding off. It's possible to program camera and object movement that moves perfectly along your pixel grid but it could be a hassle for the camera at least. You'd be limited on what speeds you could use too.
B
39
S
16
G
6
Posts: 543
Reputation: 7,619

Post » Fri Sep 04, 2015 5:32 pm

Thanks, both of you!

I really thought the solution to this wasn't going to be more complicated, so this is a great outcome. And thanks @ErekT for the detailed explanation of what's happening.

Image
B
9
S
1
G
2
Posts: 32
Reputation: 1,974

Post » Sat Sep 05, 2015 12:28 am

Glad you found it useful :)
B
39
S
16
G
6
Posts: 543
Reputation: 7,619

Post » Sat Sep 05, 2015 6:36 pm

This is useful information, thanks.

Nice art btw ;)
B
135
S
33
G
17
Posts: 1,560
Reputation: 20,734

Post » Mon Sep 07, 2015 7:56 pm

Basically, everything that is set to n*2 works smooth in construct2 ( or in computing in general ) I don't know why, but that is what my own experiments shown.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
92
S
30
G
22
Posts: 1,987
Reputation: 20,178

Post » Mon Sep 07, 2015 8:08 pm

No "power of 2" "magic" involved here ; it's just pixel rounding, which does exactly what it says.

As for n^2, it works "better" since content designed to work in n^2 can easily be accessed with data encoded on 8/16/32/64 bits, which are native data types, without waste, memory alignment or performance issues
Image
Game Producer & Independent Developer - http://raphaelgervaise.com
B
24
S
9
Posts: 237
Reputation: 2,232

Post » Mon Sep 07, 2015 8:53 pm

Refeuh wrote:No "power of 2" "magic" involved here ; it's just pixel rounding, which does exactly what it says.

As for n^2, it works "better" since content designed to work in n^2 can easily be accessed with data encoded on 8/16/32/64 bits, which are native data types, without waste, memory alignment or performance issues


Setting values to n2 did improve smoothness for me significantly.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
92
S
30
G
22
Posts: 1,987
Reputation: 20,178


Return to Construct 2 General

Who is online

Users browsing this forum: Bonne89 and 14 guests