Unity2D Devlog 20 — Dodge This, You Filthy Casual

Claudio Grassi
3 min readJul 8, 2021

With one exception, all enemies follow a linear vertical path. This movement makes it simple for the Player to shoot them down accurately. I want to introduce another level of difficulty.


Allow enemies to dodge the Player’s attacks.

How I went about it:

This challenge boils down to having the enemy detect the Player’s bullet and move to avoid it. The first thing that comes to mind is a RayCast2D. However, with this approach, the area of detection would be limited. I can therefore take advantage of another Physics2D method.

As the name suggests, BoxCast uses a rectangle rather than a Ray. For more information, please refer to the Unity Manual.

I can use this method for detecting the Player’s bullet more accurately. I, therefore, started by creating a new Script for the enemies.

First, I declare all the variables that I will need to make this work.



Claudio Grassi

Experienced digital artist, Unity game developer & coder with a knack for problem solving and a passion for video games.