All of the assets required can be downloaded here.
The sprites are in the Traps --> Platforms
Add the Platforms folder to the FileSystem
Create any level you like.
You may copy my level layout.
We will spawn Strawberries dynamically
Also, we will create scenes for a Horizontal platform and Vertical Platform
How to make the chain / rail paths
The chain is just a TextureRect node
Which uses the Chain.png image as the texture
Set the Stretch mode to Tile
Now you can stretch the image
Rotate it 90 degrees for vertical rails
Select the RailLevel node
Set the number of strawberries you plan
Create a new scene with AnimatableBody2D as the root
This is so the player will move with the platform when on it
Rename it to HorizontalRail
Choose new RectangleShape 2D
Add a new Sprite Frames resource
Click on the SpriteFrames resource
Rename the default animation to "off"
Use the Grey Off.png as the only frame
Choose the Grey On.png file
Set Horizontal frames to 8
Set Target Position Y to 10
Set Transform Position X to 17
Add an Area2D node as a child of HorizontalRail
Add a CollisionShape2D node as a child of Area2D
Add a New RectangleShape2D
Extend the Area2D collision shape above the platform
Attach a script to the HorizontalRail node
Get a reference to the AnimatedSprite2D so that
we can play the off and on animations
Get a reference to the RayCast2D so we can determine when it is no longer colliding
flag if the platform can move
The platform can only move
when the player triggers it
Connect the body entered signal
In the body entered function
Check if the body is the player
then set can_move to true
In the physics process function
continuously update the position of the platform
by move_amount x direction
How do we know when the track ends?
That's what the RayCast is for - we need something for it to detect...
Return to the RailLevel scene
Add a StaticBody2D as a child
Add a CollisionShape2D as a child
Add a New RectangleShape2D
Place the collision shape
underneath the rail track
As long as the ray cast is colliding with the collision shape
we know that we are still on the track.
In the RailLevel Scene select the StaticBody2D
Put it on its own Collision Layer (7)
In the HorizontalRail scene
Set the CollisionMask to 7
So that the Ray is looking for
the StaticBody representing the track
Now complete the process function:
if the ray is no longer colliding
move the ray to the opposite side of the platform