All of the assets required can be downloaded here.
The sprites are in the Enemies --> TrunkÂ
Add the Trunk folder to the FileSystem
Create any level you like.
You may copy my level layout.
We will place one Strawberry strategicallyÂ
Also, we will create a scene for a TreeTrunkEnemy
Create a new scene with CharacterBody2D as root
rename it to TreeTrunkEnemy
Add a CollisionShape2D with New RectangleShape2D
An an AnimatedSprite2D with Sprite Frames
Select the TreeTrunkEnemy node
Set the Collision Layer to 4 (Enemies)
Set the Collision Mask to 1 and 2
In the AnimatedSprite2D node
Select the idle animation
Now select the CollisionShape2D node
to control the firing rate
The Tree should have an area of vision
once it sees the player it will shoot atÂ
Add a CollisionShape2D node
Size the RectangleShape2D
To detect when the enemy should reverse direction
rename it to RayCastRight
Add another RayCast2D node
set Target Position Y to 20
Do the opposite for RayCastLeft
Now you have two rays to detect edges
The player can only hit the enemy from above
Add a new CollisionShape2D