Adding enemies
There are many different behaviors you could add for an enemy. For this game, the enemy will walk along a platform in a straight line and change direction when hitting an obstacle.
Scene setup
As before, you’ll need to create a new scene to represent the enemy:
- Start with a
CharacterBody2Dnode namedEnemyand give it three children:Sprite2D,CollisionShape2D, andAnimationPlayer. - Save the scene in a 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 Mask to environment, player, and enemies. As with the player, this determines which types of objects the enemy will collide with.
- It’s also useful to group enemies together, so click the Node tab and add the body to a group called
enemies. - Add
res://assets/sprites/opossum.pngto Texture and set Animation/Hframes to6. - Add a rectangular collision shape that covers most...