![]() |
towards a better layout of WalkPath() functions
Okay, I've managed to write a pottable BotWalkPath() function. It's just in alpha stage but I'd need your comments on its layout (generally speaking, since you're not supposed to know all the details of my code yet). It would be great if we could agree on the best layout for such a function since it is a very common problem for all bots, how to reach their next waypoint efficiently. Also I have a problem. But first things first, here's the function :
Code:
void BotWalkPath (player_t *pPlayer) 1°) identify the link 2°) identify extra entities that the bot can use to reach the next link 3°) decide of the action to take regarding to these 4°) if not explicitly told not to, walk towards the next waypoint Commentaries ? Note that in BotMoveTowardsPosition(), only forward/strafe keys are involved. The bot does NOT make its body angle face the waypoint while the view angles are looking elsewhere (it's unnatural). Which brings me to the problem: I need a reliable way to tell that the path is failing. How do you guys do for detecting that your bot's next waypoint has become unreachable ? |
Re: towards a better layout of WalkPath() functions
I think the simplest way would be for the bot to compare its current x,y,x location to its x,y,x location the last time the function was called.
If (ABS(CurrX-PrevX) + ABS(CurrY-PrevY) + ABS(CurrZ-PrevZ) < MinimumWalkSpeed) And ImTryingToMove Then OhCrapImStuck Else CoolImNotStuck EndIF ABS()=absolute value function I'm a VB coder and don't speak C/C++ very well. But that seems to me to be the simplest most reliable way to solve the problem. BTW, PrevX, PrevY, and PrevZ should be declared static and updated with the bot's current x,y,z coordinates as the last step before the function exits. If testing to see if jumping unsticks the bot, do the above, but without the Z coordinate (assuming jumping causes the Z coordinate to change). |
Re: towards a better layout of WalkPath() functions
Based on the bots speed and the distance to the next way point, you could calculate how long it should take in the worst case to reach the next point (in time units or frame counts). If the worst case time elapses (assuming there's no battles inbetween, or changes in speed) then you can assume the bot is not succeeding.
Another thing you could do by itself, or in combination with the first method, is calculate the distance from where the current bot position is to the next navpoint position. You could then check to see if the distance is shrinking over time (or over frames) or not. Using this method, you will have the ability to decide if the path is making fast progress, slow progress, negative progress, or zero progress. |
Re: towards a better layout of WalkPath() functions
@A$$A$$IN: this is indeed the simplest method, however it is unpractical because it won't work on a certain number of case. For example, if the bot falls down the Aztec bridge, the bot will still be in movement but the path will have failed. Also, if a path between 3 nodes make less than a 90 degree angle (circling around a wall, for example), the bot will reach the waypoint then face back and start walking the other side, and this might trigger your stuck check algorithm. One more common situation, is when the bot is already walking, then is told to walk another path that starts right behind it ; the bot's speed will decrease, stop, and then increase backwards and that doesn't mean the bot is stuck. I'm long experienced in tweaking stuck checking algorithms like this one, and unfortunately I never could reach any acceptable result.
@botmeister: your first idea looks promising! I hadn't thought about this one yet. I'll try it. Your second idea though is the traditional way to go for such algorithms when the bot faces its next waypoint perfectly, and thus is ASSURED to reach it. However mine don't, they use the strafe keys instead, and this causes problems when they come closer to the waypoint as the distance can really vary much, decreasing then increasing several times in a second, but it doesn't mean the bot is stuck though. |
Re: towards a better layout of WalkPath() functions
Quote:
I am not suggesting that you abort as soon as you detect the bot's distance is getting larger, but that you abort only if the bot is not making adequate progress over a period of time. But how to choose the period of time? I think you could estimate the maximum time to reach the navpoint (ETA) then check over time, relative to the ETA, to see if the bot is actually closing in on the navpoint or not. You could for example, choose a period of time that's 1/2 of the ETA, but I suspect it will be more complicated than that. If the bot is not closing in quickly enough, then you could abort before the ETA expires, thus saving time on an unreachable navpoint. |
All times are GMT +2. The time now is 07:03. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.