Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

The latest stuffs

The latest stuffs

O-san
O-san
OddGames development journal · · 4 min read
1,228 3
This new site design is awesome.

Though its been a while since my last journal posting I have still maintained my game projects Medieval Story and Nimrod. The lack of posts is mainly due to me being a bit lazy.

Well, anyway.. I made some changes to the editor (Nimrod the isometric editor). It now incorporates the recast and detour path finding library. This means I can now generate a navigation mesh and save it to a file from within the editor. Previously I had to create and edit the navigation mesh manually which could be very tedious, especially if there where a lot of smaller static objects that needed to be taken care of. Now I can just press the "build" button and voila! Out comes a navigation mesh in just a few milliseconds. This mesh can be made with some settings such as agent radius, max climb and slope. These are things that my previous implementation had left out. It is also possible to do searches on the generated mesh with the library (detour part of the library). This is also accomplished with just two clicks, a start and an end position.



The information text in the upper right corner is obsolete.

I have also incorporated this library into Medieval Story itself (there wouldn't be much point to it other ways, having it in the editor). So I got two knight guys walking around. One chasing the other (the player) using path finding. This looked pretty cool so I thought it would look even cooler if I had twenty knights chasing the player, why not?! So I spawned twenty knights pretty easily and they all chased the player around the map. Even the frame rate seemed reasonable though I hadn't actually done any performance checks... My vertical sync at 60 fps was still steady. There was some other problems that emerged however; When twenty knights come running and a small boulder or... say a player, is in the way of the herd he gets pushed by the accumulated force by the twenty knights. This can look a little bit silly and unrealistic, especially if it is supposed to be a heavy object that gets pushed around. There is also a problem that all the twenty knights can't fit at the same goal location (the player position). So the guys at the rear of the herd would never reach their goal and thus kept pushing the others. I think "battle positions" around the player can solve some of these issues.

A battle position is a place next to the player where an NPC can stand and hack away at the player. There is limited space for these positions. If a player would stand next to a tree or other static geometry the position that occupies the tree's position would become unavailable. I thought of this system to tackle the problem:

gallery_119664_44_11325.png
The player is the blue dot, the battle positions are the red dots. The available places an NPC can walk to is determined by the number of available battle positions. Each battle position contains an ID of which object that currently occupies it. This is determined by a ray test emitting from the player to the battle position. The ray test is performed each frame and assigns -1 to the ID value if no hit occurs. If a hit is found the ID for that object/NPC will be assigned. An NPC can then see if he occupies a battle position by checking against his own ID. If the NPC can't find any valid battle position (all positions are occupied and they are not his own) it should be safe to let that NPC stop his attack attempt and wait for a position to become available. Maybe he can cheer on the other NPC that is trying to kill the player...

This seemed like a fine solution but I quickly found out that I also need some kind of dynamic obstacle avoidance check. This image shows how things turned out:

gallery_119664_44_1246.png
Two NPC are going for the player. One NPC has already found a battle position (the bottom position with a red cross). NPC number two wants to go to the battle position right of the occupied slot (the yellow cross). But on his straight way he will be stopped by NPC number one (red cross occupying battle position) . He should instead of endlessly walking against that NPC try to go around (the yellow dots) and reach his goal. This scenario is very common when many NPC are involved at the same time but not noticeable when only one NPC is attacking.

It should be possible to achieve the yellow dotted path with some sort of obstacle avoidance. Maybe have some sort of sensor scan of the terrain ahead. Then turn left or right to avoid any small objects in front of the NPC.

Well, that's it for now. Here is a video of some path finding in action:

[media]
[/media]

Thanks for reading!

Discussion

Loading comments...