+2 votes

I'm using a character made of a KinematicBody2D with a 32x32 sprite and Camera2D attached to it. I've noticed that when I enable smoothing on the Camera2D to something around 1 through 10, the smoothing effect looks nice when the sprite moves, but seems to shake for about 2 seconds when the character stops moving. The shaking seems to go back and forth and is very noticeable, and there is no shaking when the smoothing is off. This probably results from the low resolution.

Here's a gif: http://i.imgur.com/2htpeGj.gifv

I'm using godot-2.0-stable on Linux if that makes a difference.

in Engine by (844 points)

2 Answers

0 votes

I think it is the effect of low resolution (big pixels) and no filtering. Slow movements result in "pixel jumps".

A solution would be to enable filtering, but that would destroy the pixel look.

If you mean the 1px gap between the Godot logo and your character, then you might want to take a look at the position values of those. Inspector>Node2D>Transform>Pos(x,y). If both are whole numbers, this gap should not show up anymore.

EDIT2: "whole numbers", not "even numbers". But that would have worked also. :)

by (14 points)
edited by

Actually use_2d_pixel_snapwas always off.

Have you turned off filtering for those sprites? (Texture Resource Properties > ImageTexture > Flags) It has the same effect.

Yeah, filtering is off. At first I imported the spritesheet and turned off filtering, but now I'm just using a PNG.

Just want to say I am having the same issue. I did the Texture Resource -> ImageTexture -> Flags, and checked filter. The jitterness has stopped (pixel_snap is off). Although, there is a tiny, and I mean now even tinier little jitter (smoothness 6). but it's barely noticable. Anyways, it's a lot better than before and will work fine in production. I will try @batmansab code snippet later too. Thanks Doc Angelo!

This was from a while ago, and my solution only helped a little. I need to look deeper into this problem...

+1 vote

Edit: It's better but still shaky. I still need to find a better solution...

I figured out an acceptable solution. Instead of parenting the camera to the character, I made an independent one in the main scene, then wrote my own smooth following code based on what was explained in this Unity Tutorial. The resulting code worked identically to the built in method (still shaky when the character stops), so I added a cutoff (set to 20.0 in my script) that works similarly to drag margins. So the camera stops following when it gets within the cutoff distance, which I set to just as the shaking starts. Here's the code:

func _fixed_process(delta):
        var x = lerp(get_pos().x, target.get_pos().x, lerpRate*delta)
        var y = lerp(get_pos().y, target.get_pos().y, lerpRate*delta)
        var pos = Vector2(x,y)
        if(pos.distance_to(target.get_pos()) > cutoff):
by (844 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.