In this article, I will guide you to create characters for Shooter game with Godot.
| Join the channel Telegram of the AnonyViet 👉 Link 👈 |
CREATE CHARACTERS
First of all, download the art.
Links: https://opengameart.org/content/animated-top-down-survivor-player
AnimatedSprite
First you delete the Sprite and then add yourself the AnimatedSprite node.![[Godot Shooter] #2: Create Characters & Shoot Bullets 26 [Godot Shooter] #2: Create Characters & Shoot Bullets 25](https://anonyviet.com/wp-content/uploads/2020/08/1-1.jpg)
Then Create New Frame
![[Godot Shooter] #2: Create Characters & Shoot Bullets 27 [Godot Shooter] #2: Create Characters & Shoot Bullets 26](https://anonyviet.com/wp-content/uploads/2020/08/2-2.jpg)
Then add me
3 animations are : idle – move – shoot
Handgun – Rifle – Shotgun you can get inside
![[Godot Shooter] #2: Character Creation & Shooting 28 [Godot Shooter] #2: Create Characters & Shoot Bullets 27](https://anonyviet.com/wp-content/uploads/2020/08/3-2.jpg)
Drag them all into 3
![[Godot Shooter] #2: Create Characters & Shoot Bullets 29 [Godot Shooter] #2: Character Creation & Shooting 28](https://anonyviet.com/wp-content/uploads/2020/08/4-2.jpg)
Set CollisionShape2D again.
![[Godot Shooter] #2: Create Characters & Shoot 30 . Bullets [Godot Shooter] #2: Create Characters & Shoot Bullets 29](https://anonyviet.com/wp-content/uploads/2020/08/5-2.jpg)
Code:
Next is the code. We will test if the player moves, it will run the animation move and stand still and run the animation idle, if it shoots, it will run the animation shoot.
![[Godot Shooter] #2: Create Characters & Shoot Bullets 31 [Godot Shooter] #2: Create Characters & Shoot 30 . Bullets](https://anonyviet.com/wp-content/uploads/2020/08/6-2.jpg)
Next because this is a shooter we have to let the character rotate in the direction of the mouse, then we have the command: look_at(get_global_mouse_position())
![[Godot Shooter] #2: Character Creation & Shooting 32 [Godot Shooter] #2: Create Characters & Shoot Bullets 31](https://anonyviet.com/wp-content/uploads/2020/08/7-3.jpg)
Next set the camera, let’s look at it easily:
Add the camera2D node in Zoom to make it easier to see guys.
![[Godot Shooter] #2: Character Creation & Shooting 33 [Godot Shooter] #2: Character Creation & Shooting 32](https://anonyviet.com/wp-content/uploads/2020/08/8-2.jpg)
WOMAN SUNSHINE
Next we will create bullets to shoot piu piu
Download link: https://drive.google.com/file/d/1fr4xNtR-s5qS49G5N98in3oTVlVJyxAN/view?usp=sharing
Please download.
Done then create a new sense
Original button is Area 2D to check when bullet collides
CollisionShape2D
Sprite
![[Godot Shooter] #2: Character Creation & Shooting 34 [Godot Shooter] #2: Character Creation & Shooting 33](https://anonyviet.com/wp-content/uploads/2020/08/9-1.jpg)
You drag the bullet image into the Sprite
Then set collisionShape2D too
Then change the name to Bullet
![[Godot Shooter] #2: Create Characters & Shoot Bullets 35 [Godot Shooter] #2: Character Creation & Shooting 34](https://anonyviet.com/wp-content/uploads/2020/08/10-3.jpg)
Create New Script
![[Godot Shooter] #2: Character Creation & Shooting 36 [Godot Shooter] #2: Create Characters & Shoot Bullets 35](https://anonyviet.com/wp-content/uploads/2020/08/11-2.jpg)
Here I will add a function so that the bullet can spawn somewhere you want and Damage (damage)
func start_at(pos, dir): position = pos rotation = dir velocity = Vector2(speed, 0).rotated(dir)
position =pos : means the position of the bullet will reject the pos
rotation = rotation of the bullet
![[Godot Shooter] #2: Character Creation & Shooting 37 [Godot Shooter] #2: Character Creation & Shooting 36](https://anonyviet.com/wp-content/uploads/2020/08/12-2.jpg)
Next, we will create a function to assign speed to the bullet so that it can fly
func _physics_process(delta): position += velocity * delta
![[Godot Shooter] #2: Character Creation & Shooting 38 [Godot Shooter] #2: Character Creation & Shooting 37](https://anonyviet.com/wp-content/uploads/2020/08/13-1.jpg)
Oh, remember to turn 2 buttons Sprite and Collishape Move horizontally if you don’t want it to shoot vertically
Then next we have to check if the bullet leaves the screen, it will self-destruct so that it can’t accumulate again causing lag.
Then you add the button VisibilityNotifier2D then adjust the dog is fine. Then connect the signal screen_exit (quit screen)
![[Godot Shooter] #2: Create Characters & Shoot Bullets 39 [Godot Shooter] #2: Character Creation & Shooting 38](https://anonyviet.com/wp-content/uploads/2020/08/15-5.jpg)
![[Godot Shooter] #2: Create Characters & Shoot Bullets 40 [Godot Shooter] #2: Create Characters & Shoot Bullets 39](https://anonyviet.com/wp-content/uploads/2020/08/16-3.jpg)
Then in that sentence we add the command: queue_free()
![[Godot Shooter] #2: Character Creation & Shooting 41 [Godot Shooter] #2: Character Creation & Shooting 40 . Bullets](https://anonyviet.com/wp-content/uploads/2020/08/17-1.jpg)
Then next we’ll shoot it.
Before that you need to have the bullet’s sence to be able to add it and use onready, it will be loaded when running.
![]()
Then check if key is pressed F it will shoot
![[Godot Shooter] #2: Character Creation & Shooting 43 [Godot Shooter] #2: Character Creation & Shooting 42](https://anonyviet.com/wp-content/uploads/2020/08/19-1.jpg)
get_parent().add_child(b): means it will take the parents and then add_child ie add the bullet button if there is a video, I will illustrate it easier.
b.start_at(global_position,rotation) : global_position = position of the character, rotation is the angle of rotation.
When shooting you will see it appear in the middle of the player, we need to adjust it outside the gun. Then do the following.
You add a Position2D button and then drag it to the place where you want the bullet to appear
![[Godot Shooter] #2: Character Creation & Shooting 44 [Godot Shooter] #2: Character Creation & Shooting 43](https://anonyviet.com/wp-content/uploads/2020/08/20-1.jpg)
Next is simple, you just need to add $Position2D before the global_position to spawn in the above place.
![[Godot Shooter] #2: Character Creation & Shooting 45 . Bullets [Godot Shooter] #2: Character Creation & Shooting 44](https://anonyviet.com/wp-content/uploads/2020/08/21-1.jpg)
And if you run it, you will have a situation like the picture
![[Godot Shooter] #2: Create Characters & Shoot Bullets [Godot Shooter] #2: Create Characters & Shoot Bullets](https://anonyviet.com/wp-content/uploads/2020/08/22.jpg)
And the next post will have a fix
Code Player:
extends KinematicBody2D
export var speed = 200
onready var bullet = preload("res://Canh/Bulet.tscn")
func _physics_process(delta):
look_at(get_global_mouse_position())
laydau_nhapvao(delta)
func laydau_nhapvao(delta):
var vector_dauvao = Vector2.ZERO
vector_dauvao.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
vector_dauvao.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
vector_dauvao = vector_dauvao.normalized()
if vector_dauvao != Vector2.ZERO:
$AnimatedSprite.play("move")
else:
$AnimatedSprite.play("idle")
var dichuyen = vector_dauvao * speed * delta
if Input.is_key_pressed(KEY_F):
shoot()
dichuyen = move_and_collide(dichuyen)
func shoot():
var b = bullet.instance()
get_parent().add_child(b)
b.start_at($Position2D.global_position,rotation)






