Game Juice - How I made screen shake
I made a screen shake for game juice. It's simple enough
First, I made an animation_player named CameraShake in the player scenes
Then, I made 3 animations, shaking the player's camera
In the player script, when the player takes damage, I added so that the camera will shake
func _on_hurtbox_hurt(damage, _angle, _knockback) -> void:
var rand_num = randi_range(1, 3)
hp -= clamp(damage-armor, 1.0, 999.0)
healthBar.max_value = maxhp
healthBar.value = hp
anim_fx.play("screen_hurt")
match rand_num: #<- for variation
1:
camera_shake_anim.play("CamShake1")
2:
camera_shake_anim.play("CamShake2")
3:
camera_shake_anim.play("CamShake3")
_:
pass
if hp <= 0:
death()
The match_num makes the player play the CamShake randomly, each animation shakes in a different way, so that it doesn't look boring!