KISS concept applied to scanners


Hello! 

I worked today on refining the first enemy type: Drone. Before working on the combat mechanics, I had to revisit my GDD to ensure it was aligned with my latest decisions and tweaked it a bit. Instead of creating the first enemy as a fast robot that would chase the player,  I changed to a drone that would fly over the obstacles while chasing the player due to the new layout of the room, giving the user a sense of urgency to find a good spot to shoot. Also, as it is already chasing the player automatically, I removed the projectiles from the enemy and changed it to auto-explosion after some seconds when the player is in range, making it a little easier to learn the dynamics. Not THAT easy though, as it will only explode if the player is still in range when it's time to explode. 

Ok, now that the changes are behind us, it's time to work on the mechanics! The first thing that came to mind was: How will the drone's sensors work? In real life, we have dozens of sensor types that can be used on a drone: Heat, Infrared, object detection via camera, sounds, etc. One thing in common on all of them is that there is a listener waiting for a signal to inform that something happened. 

Bringing that to our game dev world, we also have multiple options: Colliders, Raycasts (line, circle, etc.), Triggers, and so on. Most of the articles (and LLMS) about that recommended using raycasts everywhere, with no clear limitations about performance or best practices. Now, in my case, I have a drone and the only thing I need to do is to check if the player is in range (Circle around it) when it starts the countdown and if it is still there when it's time to explode. Think about it: Drones are flying over the obstacles and there is a circle around it, why can't I just use colliders? I can and I did. The only caveat is that I did use the OverlapCircleAll to detect if the player is still there as the collider might fail to do so, and we don't want people to say that AoE hit them when they were far away. 

Final decision:

  1. Use CircleCollider2D to detect that the player is in range and change the Drone to attack mode
  2. Use OverlapCircleAll while in the attack mode to confirm that the player is already there. (You can still use the collider above, but to be on the safe side I went with this)

You might be asking: Why didn't you just use the overlap circle to both scenarios? Modularization! I can use the *Collider2D to any enemy I want, just put the right script to handle the collision and that's it. However, I can't use the overlap circle to all of them, as this is a logic just for the drone. Always think about how you can reuse your logic! 

Targol.

Leave a comment

Log in with itch.io to leave a comment.