Enemies or monsters are an indispensable thing in Platformer or Rpg games. So, in this part I will show you how to design an enemy and how the design will last 2 or 3 parts.
| Join the channel Telegram of the AnonyViet 👉 Link 👈 |
Art
As for the Art part, you can download it via the au link: Desert Enemy Pixel Art Game Characters![Creating 2D Platformer Game with Godot]Part 7: Enemy Design 20 Creating a 2D Platformer Game with Godot]Part 7: Enemy Design](https://anonyviet.com/wp-content/uploads/2021/11/11-11-2021-11-12-38.png)
After downloading, in Assets create a new folder called KeThu and copy all the art into it.
Create enemies
Create a new scene
![Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 21 Creating 2D Platformer Game with Godot]Part 7: Enemy Design 17](https://anonyviet.com/wp-content/uploads/2021/11/11-11-2021-11-16-17.png)
Like Player, you will create a kinematicbody and here I rename it Cao (that fox) and add 2 more child buttons, AnimatedSprt and CollisionShape2D.
![Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 22 Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 18](https://anonyviet.com/wp-content/uploads/2021/11/11-11-2021-11-17-29.png)
You create new Frames in AnimatedSprite.
![Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 23 Creating 2D Platformer Game with Godot]Part 7: Enemy Design 19](https://anonyviet.com/wp-content/uploads/2021/11/11-11-2021-11-19-42.png)
Here I add 5 animations corresponding to art.
![Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 24 Creating 2D Platformer Game with Godot]Part 7: Enemy Design 20](https://anonyviet.com/wp-content/uploads/2021/11/11-11-2021-11-21-51.png)
This is after adding the animation and it shows up.
![Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 25 Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 21](https://anonyviet.com/wp-content/uploads/2021/11/11-11-2021-11-22-25.png)
You add CollisioShape to it![Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 26 Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 22](https://anonyviet.com/wp-content/uploads/2021/11/11-11-2021-11-22-37.png)
Done then rotate CollisionShape2D to landscape.
![Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 27 Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 23](https://anonyviet.com/wp-content/uploads/2021/11/11-11-2021-11-23-03.png)
Click on the toolbar to make adjustments.
![Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 28 Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 24](https://anonyviet.com/wp-content/uploads/2021/11/11-11-2021-11-22-54.png)
Then adjust the AnimatedSprite to fit the CollisionShape2D.
Note: You always take the CollisionShape as the alignment point and don’t change the position or something of the CollisionShape .
![Creating 2D Platformer Game with Godot]Part 7: Enemy Design 29 Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 25](https://anonyviet.com/wp-content/uploads/2021/11/11-11-2021-11-28-41.png)
Done then save the scene, I create a new folder in Scenes called Kethu and save it there.
More Scripts
Next is the code part.![Creating 2D Platformer Game with Godot]Part 7: Enemy Design 30 Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 26](https://anonyviet.com/wp-content/uploads/2021/11/11-11-2021-11-27-44.png)
![Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 31 Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 27](https://anonyviet.com/wp-content/uploads/2021/11/11-11-2021-11-29-19.png)
Add a little script.
extends KinematicBody2D
var tocdo = 60
var trongluc = 10
var chuyendong = Vector2()
var huong_dichuyen = 1
onready var animation = $AnimatedSprite
func _physics_process(delta):
chuyendong.x = tocdo * huong_dichuyen
chuyendong.y += trongluc
chuyendong = move_and_slide(chuyendong,Vector2.UP)
if is_on_wall():
huong_dichuyen = huong_dichuyen * -1
Here, it is no different from Player as it needs 4 basic variables to be able to move and 1 variable to be able to use animation.
Change direction_dichuyen because this is AI so you don’t have to press the button to move it or anything, so I’ll set it to 1 by default.
At the function _physics_process(delta):
- The first 3 lines are not far away
- Current if is_on_wall() is a function that allows you to check if an enemy child is on the move and with whom it touches.
- Below I will check if moving to the right meets a wall or something, it will turn to the left to move forward and vice versa.
![Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 32 Creating a 2D Platformer Game with Godot]Part 7: Enemy Design 28](https://anonyviet.com/wp-content/uploads/2021/11/11-11-2021-11-41-04.png)
Then you Instance the fox into the Map so you can see it has moved.
func _physics_process(delta):
chuyendong.x = tocdo * huong_dichuyen
chuyendong.y += trongluc
chuyendong = move_and_slide(chuyendong,Vector2.UP)
animation.play("dichuyen")
if is_on_wall():
huong_dichuyen = huong_dichuyen * -1
scale.x = scale.y * huong_dichuyen
At the function _physics_process(): then I added 2 command lines to be able to run the animation and rotate the image left and right.![Creating a 2D Platformer Game with Godot]Part 7: Enemy Design Creating a 2D Platformer Game with Godot]Part 7: Enemy Design](https://anonyviet.com/wp-content/uploads/2021/11/11-11-2021-11-58-43.png)
This is the result.![]()
Sometimes the Sprite will be inverted and you can correct it by adjusting the Flip_H of the Sprite or AnimatedSprite.
Summary
So in this part you can already make the most basic enemy, in the next part I will show you how to make it move on the surface.









