From 00ddc355686e7d300f0cd2fcfd1a9b0c97aeb07f Mon Sep 17 00:00:00 2001 From: ccrs Date: Sat, 25 Oct 2025 23:26:43 +0200 Subject: Core/Entities: handle more edge cases in IsInAir can be done in one liner, with one math expression if I'm not mistaken, but this allows easier debugging --- src/server/game/Entities/Unit/Unit.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index c6ff7b651de..4d118525e77 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -3166,7 +3166,17 @@ bool Unit::IsUnderWater() const bool Unit::IsInAir(Position const destination, float destinationFloor, bool honorHover/* = true*/) const { - return std::fabs(destination.GetPositionZ() - (honorHover ? GetHoverOffset() : 0.f) - destinationFloor) > 0.1f; + float z = destination.GetPositionZ(); + if (z < destinationFloor - 0.5f) // if really bellow ground, in air (caves,...) + return true; + float hoverHeight = GetHoverOffset(); // height if currently hovering + if (GetTypeId() == TYPEID_UNIT) { + hoverHeight = ToCreature()->CanHover() ? GetFloatValue(UNIT_FIELD_HOVERHEIGHT) : 0.f; // height if could hover + } + z = destination.GetPositionZ() - (honorHover ? hoverHeight : 0.f); + if (z <= destinationFloor + 0.5f) // if is bellow ground or slightly above it, not in air - should hover too + return false; + return std::fabs(z - destinationFloor) > 0.5f; // if the difference is higher than tolerance level, in air (todo: this should most likely take into account unit's "size") } void Unit::ProcessPositionDataChanged(PositionFullTerrainStatus const& data) -- cgit v1.2.3