Made many changes to the AI over the past week or so.
The latest change was to make the AI respect its navgrid 'island', and not try to go off it in two cases that weren't previously handled : being out of range of the player, and finding no path to the player despite increasing the search range dramatically.
In both of these cases, the code was just having the AI choose the player's last known position as the destination. This doesn't work if the player & the AI are in different nav-grid islands, so I added code to fix that.
I also just optional added bounding box restrictions to the AI pathing, where you can force all pathing to be done to destinations inside a given trigger box. The AI may choose a path outside the box ( although rarely ), but will only choose destinations inside the box. The box is adjusted to respect the navgrid island as well.
The enemy up/down aiming has never been quite right. I got the gun muzzles and laser sights working a while ago, so the bullets come out of the right spot, as do the laser sights, and the AI was already able to rotate its arm up & down appropriately to aim at the player.
Unfortunately, on my new level with a large pit, if I stood there, the lower AIs were consistently undershooting my position. I tried a few hacks by making them aim higher up on my guy's body, and also tried adding a fixed percentage to the elevation height, but it was just not right.
Here is a shot of the enemies shooting mainly below my char's feet when far below him.
Especially note the orange trails from the center of the pit - not even close.
So, today, I finally tracked down and fixed the issue. The old code would create a vector from the AI's center, to the player's center, then normalize this, and take the y part and store it as the elevation for later.
If would then set the y to zero, and normalize the vector to act as the character's facing vector. This way the characters are always upright, and don't lean back when trying to fire upwards.
Later, when the animation code is run, the elevation y axis value is retrieved, put into facing.y, and then renormalized, and used for the muzzle, laser sight, and firing directions.
There are two issues with this approach. One is that the multiple normalization with y set to zero and elevation is not invertible. You can't just put in a y component, normalize, then take it out normalize, then put it back, normalize, and get the original vector back. Doesn't work that way.
So, I fixed the other issue ( measuring from the real muzzle position instead of the enemy center ), and make the AI aim for not the char center, but the closest point on his capsule centered height-wise.
I also changed the elevation to store as an angle instead of a y coordinate, and changed the code to use asin instead of atan for the derivation, which is more accurate, although atan 'worked' bc the enemy's arm happened to be ~ 1 meter long.
So, now it works great, and the enemies can tear you up from above or below.