Day 10. Secondary Fire Power-up.

Dmitry Gordeev
1 min readNov 26, 2020

--

I choose to develop a homing laser as a secondary fire power-up. The task was open about what kind of gun to build. So, it was intriguing for me to learn how to navigate the laser to follow and reach a target. After some research, I learned that I can use Rigidbody2D component that can navigate laser after a vector calculation.

By setting up “velocity” and “angularVelocity”, the laser starts to do what I imagined it would.

Credit goes to this tutorial https://www.theappguruz.com/blog/create-homing-missiles-in-game-unity-tutorial

Another discovery was this method OnBecameInvisible() which is called every time an object moved out of the camera. That is the perfect condition to destroy a laser if it out of the screen. Cleaned up the code. Neat!

One more thing left to mention. Target search programmed to find the nearest enemy. I have done it by measuring the distance between all active enemies and the player. Vector3.Distance(enemy.transform.position, transform.position); Minimum distanced enemy being targeted.

--

--

Dmitry Gordeev
Dmitry Gordeev

No responses yet