Enemies follow a similar structure to the Player
So start by duplicating the Player scene
Enemy doesn't need Camera2D
Detach the script from Player Node
Diconnect the animation_finished() signal
Go through all the animations
Go through all the animations
Replacing them with the assets
from the Mobs => Cactus folder
Rename the root node to Enemy
Add a Timer node to the enemy
Set the timer to autostart
Add a script to the Enemy
Save it as enemy.gd in the scripts folder
Now connect the Timeout signal of the timer to the script
The enemy will need a reference to the Player
Create an onready variable for this
Create some variables to trackĀ
When the enemy is wandering the map
we want to randomly change direction
create variables for this
Code the timeout method of the Timer
find the distance between the player and enemy
if in range, turn towards the player
if too far from the player
start moving towards them
start wandering in a random direction
Now code the physics process
so that if enemy collides
it turns and moves in a random