Godot Version
4.7.stable.flathub [5b4e9cb0f] (being run on Bazzite)
Question
Hello! I am following along with CatlikeCoding’s Godot tutorial, specifically the Conveyor chapter (see: Conveyors - True Top-Down 2D ). In it, instead of using a Sprite2D child node for the sprite, they instead point followers to utilize a Line2D node, setting the Texture to their provided conveyor.png image, and changing the CanvasItem material to be a customized shader to make the image looking like moving arrows.
Unfortunately, while following the tutorial has enabled me to create a functioning, customizable set of conveyors, they are invisible, and after a few hours debugging I am at a loss. Below is what I have in my project at this time - my biggest fear is that its a version issue, as the tutorial chapter is written for Godot 4.5. Is there an obvious area that the issue may be? If there isn’t one, and this simply cannot work on 4.7, is there a suitable alternative that would be recommended?
conveyor struct
Area2D base node, with child Collisionshape2D and Line2D nodes. As displayed in code below, default node has CollisionShape2D and Line2D assigned, as well as Length set to 32 and speed to 30 by base.
CollisionSHape2D is a RectangleShape2D of size (32, 10) and Resource set Local to Scene on.
Line2D has a baseline PackedVector2Array of size 2, with default points both set to (0.0, 0.0). The width is set to 12.0. The Fill → Texture is set to the conveyor.png (a 12x12 pixel file of black + arrow), and the Texture Mode set to Tile. Under the CanvasItem → Material is set to ShaderMaterial, with Shadower conveyor.gdshader, and Local to Scene set to On.
conveyor.gd
@tool
extends Area2D
@export var collision_shape: CollisionShape2D
@export var line: Line2D
@export_range(12, 400) var length := 32 :
set(new_length):
length = new_length
if line and line.points.size() == 2 and line.points[1].x != length:
line.points[1] = Vector2(length, 0.0)
collision_shape.position = Vector2(length * 0.5, 0.0)
var rect := collision_shape.shape as RectangleShape2D
rect.size = Vector2(length, 12.0)
## Conveyor speed, in pixels per second.
@export_range(0, 60) var speed := 30 :
set(new_speed):
speed = new_speed
if line:
line.material.set(
"shader_parameter/speed",
speed / line.texture.get_size().x
)
var objects: Array[InteractiveObject] = []
func _physics_process(_delta: float) -> void:
if objects.is_empty():
set_physics_process(false)
return
var push_velocity = transform.x * speed
for object in objects:
object.push(push_velocity)
func _on_body_entered(body: Node2D) -> void:
var object := body as InteractiveObject
if object:
objects.push_back(object)
set_physics_process(true)
func _on_body_exited(body: Node2D) -> void:
var index_to_remove := objects.find(body as InteractiveObject)
if index_to_remove >= 0:
objects.remove_at(index_to_remove)
conveyor.gdshader
shader_type canvas_item;
uniform float speed = 1.0;
varying vec4 vertex_color;
void vertex() {
vertex_color = COLOR;
}
void fragment() {
COLOR = texture(TEXTURE, vec2(UV.x - TIME * speed, UV.y));
COLOR *= vertex_color;
}
