Unity2D Devlog 19 — Beating Them To It

Claudio Grassi
2 min readJul 7, 2021

In my last DevLog, I wrote about giving enemies the ability to destroy power-ups. I realized that the result might have been too powerful. With that in mind, I will try to balance out the equation with an additional tool that the player can use.

Objective:

Add a magnetic mechanic to attract power-ups.

How I went about it:

The idea is simple. The player can press a key, and any powerups within range should gravitate to their position. My first step was to create a Script to implement the attraction behavior.

With this simple Script, I control the power-up’s attraction state with a bool. I then move the power-up towards the Player so long as the condition remains true.

The next step was to create a method in the Player Script to activate the attraction bool.

By pressing the ‘C’ Key, this code will look for all instances of the AttracBehavior Script. Once it has found them…

--

--

Claudio Grassi

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