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.
In Update()
I check for the condition below, and if it returns true, I activate the ramming behavior.
Just like that, if the Player is within range and the alien has not moved past them, the Ramming() method will be called.
Conclusion:
I could have gone a different way with this. I could have had the alien chase the Player around. However, I did not want to make a game that was impossible for the player to beat. Part of the fun comes from the feeling of empowerment. If a Player feels powerless, the game becomes a frustrating mess. So making sure that the game mechanics are balanced is just as important as making them fun.