How to create top-down 2D conveyor belts?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Demogo

I am trying to create a system in which you can build 32x32 sized conveyors to create a conveyor belt system. So far I have the building and instancing created, but the problem I am running into is that with how the conveyor belts interact with objects that touch them.

I am using a KinematicBody2D for the item being placed on the conveyor belt and an Area2D for the conveyor belt itself.

The solutions I have tried so far have not worked properly, like trying to set the velocity of the item when it enters and leaves a conveyor belt.

Conveyor Belt:

extends Area2D

func _on_StraightConveyor_body_entered(body):
	if !body.velocity == null:
		body.velocity.x = 100
		print("just touched")

func _on_StraightConveyor_body_exited(body):
	if !body.velocity == null:
		body.velocity.x = 0
		print('just left')


extends KinematicBody2D

var velocity = Vector2()

func _physics_process(delta):
    velocity = move_and_slide(velocity, Vector2())

With this solution, when the item moves along one conveyor belt, everything works as it should. But, if I add two or more conveyor belts in a chain, the item moves off the first conveyor belt, but then stops when it reaches the second.

Does anyone know a different solution I could use to achieve the goal of being able to move an item along multiple conveyor belts without these stops?

:bust_in_silhouette: Reply From: flurick

I guess the item exits the previous belt slightly after entering so it overwrites the velocity with 0, maybe?

One alternative that comes to mind is to use the gravity setting of area2d nodes instead.

Making the item a rigidbody instead of a kinematic, so that it reacts to gravity.

Set the “default gravity vector” to 0,0 in the project settings, so gravity is not “down” anymore.

And then set the belts area2D “space override” to “replace”.

It even works as expected with rotating belts if you add this line to their script

func _ready():
gravity_vec = Vector2.DOWN.rotated(rotation)