Of course this was just a temporary combat mechanic designed more for testing other functionality such as line of sight, my finite state machine and weapon controls. But now the time comes for something more advanced.
Initially I thought about terrain analysis and tactical assessment on the fly, something I'd be forced to do if I was working with robotics or something more physical but that idea rapidly gave way to storing valuable information on the map.
So to my scene I added a node named "Cover" to this node all objects that could be used as cover would be attached, things like crates, sandbags maybe a table. Things to obscure the line of sight but still allow the AI to shoot at the player. This list of cover objects would then be loaded and stored in an object designed to provide global information to the NPCs. An object which could also be used to relay communications between troops alerting other allies if they have a man down and should be on alert for the player. But enough of that I'm getting sidetracked (maybe if I updated more regularly I could have wrote about this in another post).
So I had my cover list and I changed the finite state machine to get the AI to put cover between it and the player upon sighting the player. And one thing became clear. The player just walked through the cover.
So I regenerated my navigation mesh trying to get it to account for static scenery and found that the JMonkey navmesh (which in turn is a wrapper for a previous version of the critterai library) doesn't factor in other models for the navmesh.
Right now I saw two choices:
- Edit the source code to fix this
- Use the navmesh pathfinder for a generalised path then tweak this dynamically to avoid obstacles
Upon looking at the source I decided to go for option 2. Plus it would allow for objects to move from start position which is definitely more flexible.
So how to do this...
Well here goes my method.
I cloned the bounding boxes of all cover objects as you can't get dimensions from models directly. I then added the radius of my AIs collision shape to this. The reason for this is when checking if the AI can fit between two obstacles its easier to expand the bounds for the obstacle and shrink the AI down to a point with an infinitely small width.
Then any overlapping bounding boxes I merged as the AI couldn't fit between those two obstacles. I then performed ray casts between each pair of adjacent way points on the path checking for intersections with the bounding boxes.
Any bounding boxes I collided with I took the position of the midpoint of the segment of line that intersected the box. Then I created a vector starting at the centre and moving to the midpoint and extended that by the width of the bounding box.
For a tighter fit I might want to perform another raycast to find the edge of the box were the character can walk and just brush the sides of the obstacle (remember I extended the bounding box) but for now I'm happy with this fix. It's still a work in progress and I've still got to fully test how far I've built before optimising it.
So without further ado a screenshot. The blue box is the AI, the grey box some cover, the pink dot is set above the centre of the bounding box (which is invisible), the cyan dot above the midpoint. And finally the red dot is the detour point to avoid hitting the cover.
The green line I drew in to show the ray going between the end way point behind the cover and the one prior to it.
![]() |
Cor' blimey check out that FPS! |
I'm quite proud to say it, the skin was made in photoshop by brush. I used these brushes and followed the tips http://www.brusheezy.com/brushes/1752-skin-textures-v1 they've also made my clone brushing look smoother can't recommend them enough!
No comments:
Post a Comment