The Path of the Game Dev — Day 15

Gabrielle Igarta
2 min readDec 11, 2020

Saving progress…

— —

How do you get a spaceship to dodge a bullet?

Through raycasting!

Or, at least, that’s what I’m working on at the moment. The day started with reading up on raycasting because, to be honest, I had no idea what raycasting was or how to use it.

For starters it solves the requirement for the aggressive enemy to attempt to “ram” into the player if they are close by. Depending on what you decide to cast, raycasting will detect other objects in a line, ray, circle, or box from its origin point. So I set up a circle cast on my aggressive enemy and added the appropriate code to manipulate the cast to be slightly in front of the enemy. After fiddling around a bit, I was able to move the function to move the aggressive enemy towards the player into the if statement where the player hits the circle cast. That way the enemy isn’t constantly moving to the player and that movement only happens when the above if statement occurs.

The second enemy that I started implementing similar functionality to was an evasive enemy that dodges the player’s lasers. Using the circle cast, this enemy transform moves away from the laser or player transform by reading the tags and then adding to the distance between the two transforms over time. At the moment there are a few problems I’ve noticed, most notably among them that the enemy will sometimes move towards the object it is supposed to move away from! Ugh, if only I was better at math…

Biggest takeaways from the day: Where would I be without raycasting?

— —

Progress saved!

--

--