Conveyor belt for 2D side-scolling platformer

Godot Version

4.3

Question

I’m trying to create an obstacle in my 2D platformer that acts as a conveyor belt but I’m kind of stumped and google was no help.

The idea is to use an Area2D to determine when the player is standing on the belt, and when they are, do the following:

  1. Automatically move the player in the direction of the belt while they’re standing still
  2. Slow their movement speed when they are moving in the opposite direction of the belt’s movement

So, if they belt is moving to the left and the player is standing on the belt, the player moves to the left, and if the player moves to the right while the belt is moving left, the player moves much more slowly.

I’m using this tutorial:

Making a Better 2D Movement Controller (Part 1)

so my player movement and input are in separate components. My movement component looks like this:

image_2024-09-24_123019816

When I alter the speed variable directly, it makes my character move at a slower speed, as expected. But when I try to change the speed variable from inside my conveyor script like this:
image_2024-09-24_123445377

so that it is reduced to fifty while standing on the belt, it doesn’t work. How else would I be able to slow the player while they’re standing inside the Area2D? And how would I go about automatically moving them in the direction of the belt as long as they’re not giving any input?

Apologies for the lengthy post, I’m just trying to be as thorough as I possibly can in explaining how my game is structured and what I’m trying to accomplish.

Well, I feel silly. That was way more simple than I was making it.

1 Like

Uh simple,

Assuming you have a CharacterBody2D as a player, use an Area2D as collisionshape with a signal connecting to the player.

make a var called x_position
velocity.x = x_position and the other way around. Reply if you need more info, its actually more fun to figure it out yourself! :slight_smile: :smiley: