Unity2D DevLog 17 — Check Your Rear-View Mirror

Claudio Grassi
Geek Culture
Published in
3 min readJul 5, 2021

--

Rushing headlong into swarms of enemies is a fool’s errand. Guns blazing, you do your best to shoot down as many as possible. Inevitably, a few will get past you. That’s the way it goes sometimes. Good riddance.
Aha! You let your guard down. You had better check your rear-view mirror because enemies can now shoot back at you.

Objective:

Create an enemy that shoots back at the player once it gets behind them.

How I went about it:

The idea here is to make an enemy that shoots backward at the player. When this new enemy gets behind the player, it will detect them and fire a projectile. I don’t want it to happen only when the player is directly behind the alien. I want there to be some wiggle room.

Out of the many options available to me, I chose to use:

Vector2.Dot() returns a single value based on two vectors. When the vectors are normalized, the value this operation returns will be between -1 and 1.

I can use the resulting value to figure out the position of the target object. You can visualize the…

--

--

Claudio Grassi
Geek Culture

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