Menu
CoddyTech

Screen Shake

Part of the Game Feel section of Coddy's Godot journey. Lesson 11 of 23.

A screen shake marks a big moment, like a stomp or an explosion. In this level, E calls the camera's start_shake(), which sets shake to 12. Nothing moves yet.

A Camera2D has an offset, a Vector2 that shifts the view without moving the camera node. A new random offset every frame makes the view shake.

offset = Vector2(randf_range(-shake, shake), randf_range(-shake, shake))

The shake must stop. Bring shake down toward 0 every frame with move_toward, so the jumps get smaller.

shake = move_toward(shake, 0.0, 30.0 * delta)

When shake reaches 0, both random numbers are 0, and offset is back to Vector2(0, 0).

challenge icon

Challenge

Medium

In _process:

  1. bring shake toward 0 by 30.0 * delta with move_toward,
  2. set offset to a random Vector2 between -shake and shake on each axis.

Then press E to stomp.

Try it yourself

extends Camera2D

var shake = 0.0

func _ready():
	limit_left = 0
	limit_top = 0
	limit_right = 1600
	limit_bottom = 360

func start_shake():
	shake = 12.0

func _process(delta):
	pass
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Game Feel

Practice on your own: Godot playground