All of the assets required can be downloaded here.
The sprites are in the Traps --> Spiked Ball
Add the Spiked Ball folder to the FileSystem
Create any level you like.
You may copy my level layout.
We will place some Strawberries strategically
Also, we will create a scene for a Spiked Ball
Create a new scene with a Node2D as root
Add a Sprite2D as a child
Use the Chain.png as the texture
Duplicate the Chain 5 times
Everything is overlapping - that is fine because we will reposition everything dynamically
Add an AnimatableBody2D as a child of SpikedBall
add a new Sprite2D as child of Ball
use Spiked Ball.png as the texture
add a CollisionShape2D as a child of Ball
Add an Area2D as a child of Ball
Add a CollisionShape2D as child of Area2D
Attach a New Script to the SpikedBall root node
The ball can either swing or rotate
create an enum called Mode with values
Create export variables to set
the mode (default is SWING)
the spacing between chains
Create variables to track
to the starting position (0, 0)
set the angle with a sine wave
for back and forth motion
repeatedly change the angle over time
Still in the process function
we must update the position of
each chain as well as the ball
so we repeat the same actions
for every child node in the scene
place each link in the chain 20 pixels apart
update the global position to
the value of center plus the offset
move to the next child node and repeat
Finally Connect the body entered signal
Code the body entered function
so that if the body is the player
you call the hurt function of the player
In the SpikedBall Level Scene
You can add static Chain Sprites