Add a new script to the Enemy node
Speed
Gravity
Facing direction
In physics process add gravity
Flip the sprite to face direction of travel
Call move and slide to register collisions
Check if any collision was with the player
If it was call the hurt function
If the normal is not 0, we have hit a wall
Bounce the enemy off the wall
Finally, if the enemy falls of a platform
The enemy should detect ledges
Add a RayCast2D as a child of Enemy
Rename it to FloorDetector
Set Target Position to 0, 25
Slightly ahead of the enemy
You can add a constant for this
Keep the detector ahead of the enemy
Add a check in physics process
Update the loop after move and slide
to call the new turn around function
Add an instance of the Enemy Scene to your Level01 Scene and play test.
Select AnimationPlayer, Add a new Animation called death, Set duration to 0.3s, Set Snap to 0.05
Replace the current texture
Keyframe Frame 0 at start, Keyframe Frame 5 at end, Set Update Mode to Continuous
Create a take damage function
update the physics process
to call take damage on enemy
when player stomps it from above
Play test the game to check it works as expected.