Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

AI Updates

Sign in to follow this  


AI Boundaries

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.

AI Aiming

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.

Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!