Game Dev in Progress… Day 15

Cristian Aspacio
2 min readNov 11, 2020

--

Photo by Clément H on Unsplash

Hello and happy Tuesday. Today I made some good progress and got to finish my goal for the day. My goal was to finish two features which was the Pickup feature and the Enemy Avoid Shot feature. The Pickup feature would allow the player to press and hold down the C key to make power ups float towards them. The Enemy Avoid Shot feature was to implement a new enemy type that would avoid a laser shot from the player when it’s near it. The Pickup feature was relative easy but the latter one was harder then I expected.

The Pickup feature used relatively simple code and logic to work. I simply implemented a method where the script would check if the C key was being pressed. If it is, grab the position of the player and then use the Vector3 move towards method to move the power up to the player’s position. This will only work if you hold down the key, if you don’t it will revert back to its regular movement of going down the level.

The Enemy Avoid Shot feature was super hard to implement. My logic was that if the laser was near the the enemies position, move the enemy away from the laser at a certain speed. So the first problem in this is to find a way to detect the laser. I tried a lot of different solutions such as using Ray Casting which I did for one of the previous features, but I found out a better solution. After looking around a bit more I stumbled upon Physics2D.OverlapCircle. These method creates a circle around a position given a radius and any objects with a Collider would be detected by it. This was the perfect solution to my problem. Using this method to detect enemies, now I had to figure out how to move away from the laser. Fortunately, I found a simple solution to this. By multiplying the maxdistancedelta parameter of the Vector3 movetowards method, it reverses the direction of the move.

The last feature was really tough and hopefully it will give me some insight on solutions or methods that I can use for future challenges. A lot of my solutions for these problems tend to be modifications of similar solutions I’ve already implemented. Others are also just found online and they usually work really well and just needs a bit of a modification. As always, thanks for reading!

_

Cristian Aspacio

--

--

No responses yet