Unity2D DevLog 16 — Ramming Speed
As the player, you spend a lot of time avoiding collisions with your enemies. Dodging is made easy by the fact that enemies move predictably. But I want to throw a wrench into that scheme. Sometimes, trouble comes looking for you, and all you can do is face it head-on.
Objective:
Create an enemy that will attempt to ram the player.
How I went about it:
Fundamentally, this is a question of movement. I had to decide how to move an enemy normally and switch its behavior based on the player’s proximity. But before any of that, I drew some new sprites.
With the artwork completed, I was ready to implement my Ramming Script.
I start by defining the speed and range at which the alien will attempt to ram the player. Next, I create a reference to the Player’s Transform Component. Finally, I use the Player’s Transform Component to check for distance compared to the value of Range.