0 votes

Sometimes when the camera moves it shows this weird visual tile glitch. What could be the cause, and where should I start looking for a solution?

The game is stretched in viewport mode, gpu pixel snap is on. Camera smoothing is turned off, all movement is done by code.

glitch still
glitch gif

Godot version 3.3.2
in Engine by (34 points)

Not sure what causes this but there is a GitHub repo for bugs in Godot.

1 Answer

0 votes

I think the problem is with your code

the way you move your camera might be a little buggy can you showcase your camera movement code

by (181 points)

Thanks for having a look!
By the way, although I've changed nothing on the camera, I haven't spotted this glitch in a while, which is weird.
Anyway, here is the camera movement code, it's a look ahead camera:

extends Camera2D

export var look_ahead_factor = 0.2

# look ahead shift in direction
export var shift_duration = 0.8

var facing = 0

onready var prev_camera_pos = get_camera_position()
onready var tween = $ShiftTween
#onready var player = get_parent()

func _ready():
    # adjust limits based on tilemaps in scene, function omitted in this paste

func _physics_process(delta):
    # update camera offset to always look ahead
    prev_camera_pos = get_camera_position()

func check_facing():
    var new_facing = sign(owner.velocity.x)
    if new_facing != 0 && facing != new_facing:
        facing = new_facing
        var target_offset = get_viewport_rect().size.x * facing * look_ahead_factor
        tween.interpolate_property(self, "position:x", position.x, target_offset, shift_duration, SHIFT_TRANS, SHIFT_EASE)

i found the problem

you are running a tween inside a process which will cause lagging because as your camera move your tween will need to recalculate the speed at which your camera move to the target and the closer you get the speed will keep changing causing the glitch.

I will advice to use signal as a trigger for your camera movement which will make your tween only run once

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.