I’ve been working on utilizing raycast in some newer ways to find out if I could work on some Pathfinding. I decided to start a new game that uses a randomly generated map, there’s a few enemy tanks that will wander around the map, and I’ll explain how they work. Wandering is the first step to pathfinding because the tank needs to know which directions it can go without hitting an object
There are 3 raycasts. One pointing ahead, and two pointing to either side. When the center raycast hits a wall, the tank will recognize if it’s about to hit something. It will turn either left or right, unless the side raycasts detect a wall, in which case it will not allow. In the case of a dead end, if all 3 casts are active, the tank will turn completely around.
If a tank is traveling down a corridor and detects there’s an opening (via side raycasts) it may turn and travel down that corridor instead of continuing straight.
Here’s the REAL fun. If a tank ever detects the player, it runs a raycast in the direction of the player, If that raycast hits, it has a line of sight on the player and will attempt to fire at them if it can rotate it’s gun fast enough, but it will not chase them.
If a tank detects that there’s a strong breakable block it will drop a bomb, this bomb goes off after 10 seconds and will hit anyone in its radius, but will also allow the tanks another option. (They aren’t that smart and may blow themselves up in the process)