Day 18 RayCast learned
Today, I got a couple of more segments completed. First thing on my list was to create an aggressive behavior for my enemies.
I managed to do this with find object with tag attached to type2 enemies. Also learned Vector3.Distance, to let the enemy know how many units that the player is away from the player and if it’s within a certain range of units then try to “Ram” the player.
Before our program group meeting I also managed to create a behavior that checks to see if the player is behind certain enemies.
Creating this behavior led me to learn and understand RayCasting.
This algorithm casts an invisible beam in the environment from 1 object to another. It then checks if anything passes or is being hit by the beam.
This algorithm can be used in both 2D and 3D environments. It was perfect to create the “check behind” behavior that I was creating.
I spent some time writing a method that uses Ray Cast to check to see if the player is above the enemy, I finally got it to shoot my missile projectile to shoot from out of the enemy when the Ray Cast was hitting the player in an upward direction.
A bit of a challenge was pinpointing exactly where on the object I needed to start the Ray Cast. Since it detects objects with a Collider or RigidBody ( The enemy has both), the script was telling me that the Ray Cast beam was hitting the enemy. So I had to start the beam just outside the collider’s frame.
I only have a couple more segments to finish before I start the Boss Enemy for this little 2D game.
I am super excited to move forward and ready to learn more Dev skills while finishing this cool project.