0 votes

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')

Item:

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?

Godot version Stable 3.2.3
in Engine by (12 points)

1 Answer

0 votes

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)
by (911 points)
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.