The-Cataclysm-Preservation-Project / TrinityCore

Archived repository for WoW 4.3.4.15595. The project will be reworked for Cataclysm Classic as an official new branch of TrinityCore at https://github.com/TrinityCore/TrinityCore
GNU General Public License v2.0
237 stars 97 forks source link

Non-flying NPCs walk in air and through objects and terrain. #345

Closed AGandrup closed 1 year ago

AGandrup commented 2 years ago

Description:

Non-flying NPCs can walk in the air and through objects/terrain. This happens when the NPC is chasing its target thus generating a path to its target. For the most part, this bug occurs when the NPC cannot see its target (Out of Line of Sight).

Current behaviour:

Non-flying NPCs can generate a path to the target that it is chasing, regardless of the path being valid or not, causing it to walk in the air and walk through objects/terrain.

Expected behaviour:

If no valid path is available the NPC should stand still and eventually reset.

Steps to reproduce the problem:

It can be a bit difficult to reproduce as it depends on where you are standing. But anyway:

  1. Have flying enabled. .gm fly on
  2. Aggro an NPC.
  3. Fly ontop of a building, wall or any area that are unreachable without flying - though you must still be in aggro range to keep the NPC chasing you.
  4. When you find a spot, keep adjusting your position on that area. Watch the behavior of the NPC. If you notice it start walking in the air, then stand still and you should see it walk all the way up to you.

Video of the problem:

https://www.youtube.com/watch?v=QCsooLd2XwA

TC rev. hash/commit:

TrinityCore rev. c9d9066cfa26+ 2022-04-02 17:52:10 +0200 (dev-blizzlike branch) (Win64, Release, Static) (worldserver-daemon)

TDB version:

TDB 434.22011

Operating system:

Windows 10

Notes:

I have somewhat solved the problem however I am not happy with solution which is why I haven't made a PR. I have tried quite a lot things and what seems to work the best so far, is just checking the difference between the NPCs end position and its current position and see if the end Z position is higher than the current Z position and if the end X and Y positions are too close to the current X and Y positions. Unfortunatly, doing it this way kinda breaks path finding in a way so that NPCs wont walk to you if you are right above them even though there is a valid path leading up to you.

A proper solution (I think) is to "look one step in the future" - So basically check if the Z position of the NPCs next step is higher than the next steps' FloorZ position. If so, then we know that the NPC is trying to walk in the air and we can just simply prevent it from moving. Unfortunatly I haven't really found my way to do this yet, which is why I am now opening an issue.

Ovahlord commented 2 years ago

What npc did you test this with?

AGandrup commented 2 years ago

It can happen with any npc. I posted a video in the description where i test it with a few random mobs

AGandrup commented 2 years ago

Managed to come up with a solution, which turned out to be quite simple. Please see PR #346

Warpten commented 2 years ago

Can't you just check if the path type isn't PATHTYPE_SHORTCUT?