Fix for mobs and pet movement - Updated
I've been messing around with the code to make mobs move smoothly instead of jumping on top of you. I re-wrote portions of the Mob::CalculateNewPosition to use a more refined approach to moving. Also, I changed all references to CalculateNewPosition2 to use CalculateNewPosition.
This was developed and tested on 0.5.3 DR2 code. In MobAI.cpp, just drop in this code to replace the old function: Code:
bool Mob::CalculateNewPosition(float x, float y, float z, float speed) { In MobAI.cpp, in the Mob::AI_Process function around line 892 Code:
else if (AImovement_timer->Check() && !IsRooted()) { UPDATE - This is probably as good as it will get. Until the server can know the Z coordinate for each X,Y (or at least be pretty close), the mob will not handle large vertical changes between 2 way points that are far apart, such as steep stairs. My suggestion is to make a way point at the top and bottom of such things as stairs and hills. I've tested the code out on Windows with great success. There is still some refining that needs to be done, but this gets us alot closer to properly moving creatures. -Valdain [Edit] - Fixed code after talking with Doodman |
I'm going to give this a try on the Scorpious2k Server wityh a couple of exceptions:
The Z coord calculation is important. In hilly areas or where a dest is lower than the start position you will find NPCs walking on air, This is not good. :-) And if the dest is lower, either the NPC moves underground or the client goes nuts resetting the position to the surface. For these reasons, I uncommented the line where the Z values are calculated, My other change for our purposes was to change Mob::CalculateNewPosition2 to Code:
return CalculateNewPosition(x, y, z, speed); We will be trying this today. |
I noticed in my testing that "gravity" is applied to the mob elsewhere and you don't get floating or "buried" symptoms on the client. Let me know how adding the Z calcs back in work for you. I'm just getting familiar with the code base again, and there have been lots of updates since a year ago.
As for the function naming, it really isn't consistant in the code between CalculateNewPosition and CalculateNewPosition2, but the code is the same in both. My main goal was just to improve the function. Feel free to adjust to however needed. I know most coders will #ifdef to allow for easier testing. Let me know how it goes for you and thanks for taking a look at it! -Valdain |
Quote:
The change is live on our server. Feel free to drop in and check it out. That goes for anyone else who may be curious about the this change. |
I notice with the Z calcs back in the mob will do a little fall every once in a while. The right way to fix this is to determine what the Z coord is at the new position and set it that way, but I have no idea how to do that.
To see what I mean, attack a mob, then walk backwards away from it. It seems to be most prenounced when it is chasing you uphill. -Valdain |
Re: Fix for "jumpy" mobs and pets - Updated
One note:
Code:
... Code:
... |
Re: Fix for "jumpy" mobs and pets - Updated
Quote:
|
This seemed to work very well for me...
One small problem i noticed thatmay or may not be related is lets say i fight a mob then mem blur him, when mob walks back to spawn spot, i can see him walk about 5-10 paces, the mob usually keeps walking right past spawn spot then dissapears until next reboot. |
Scorp, since you applied this to your server and checked it out, do you mind investigating merging it in?
|
Quote:
|
One little snag....
The original code this was designed to replace has been redone. Mob::CalculateNewPosition and Mob::CalculateNewPosition2 are no longer identical. Major changes have been made while this discussion was ocurring, making a direct merge of the new code impossible. It looks to me like many of the ideas have been applied, although not as a merge of the code. Here is what we have now: Code:
bool Mob::CalculateNewPosition(float x, float y, float z, float speed) { Code:
bool Mob::CalculateNewPosition2(float x, float y, float z, float speed) { So, should we try to merge in the logic from each version? Merge the code anyway? Test both versions and pick the best? Opinions? |
All times are GMT -4. The time now is 06:15 AM. |
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.