Enemies
Currently, the map is very lonely, so it's time to add some enemies to liven things up.
There are many different behaviors you could create for an enemy. For this project, the enemy will walk along a platform in a straight line and reverse direction when hitting an obstacle.
Scene setup
Start with KinematicBody2D
with three children: Sprite
, AnimationPlayer
, and CollisionShape2D
. Save the scene as Enemy.tscn
in a new folder called enemies
. If you decide to add more enemy types to the game, you can save them all here.
Set the body's collision layer to enemies
and its collision masks to environment
, player
, and enemies
. It's also useful to group the enemies, so click on the Node
tab and add the body to a group called enemies
.
Add the res://assets/opossum.png
sprite sheet to the Sprite's Texture
. Set Vframes
to 1
and Hframes
to 6
. Add a rectangular collision shape that covers most (but not all) of the image, making sure that the bottom of the collision shape is aligned with the bottom of...