Skip to content

Commit 00ddc35

Browse files
committed
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
1 parent c5e2a94 commit 00ddc35

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/server/game/Entities/Unit/Unit.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3166,7 +3166,17 @@ bool Unit::IsUnderWater() const
31663166

31673167
bool Unit::IsInAir(Position const destination, float destinationFloor, bool honorHover/* = true*/) const
31683168
{
3169-
return std::fabs(destination.GetPositionZ() - (honorHover ? GetHoverOffset() : 0.f) - destinationFloor) > 0.1f;
3169+
float z = destination.GetPositionZ();
3170+
if (z < destinationFloor - 0.5f) // if really bellow ground, in air (caves,...)
3171+
return true;
3172+
float hoverHeight = GetHoverOffset(); // height if currently hovering
3173+
if (GetTypeId() == TYPEID_UNIT) {
3174+
hoverHeight = ToCreature()->CanHover() ? GetFloatValue(UNIT_FIELD_HOVERHEIGHT) : 0.f; // height if could hover
3175+
}
3176+
z = destination.GetPositionZ() - (honorHover ? hoverHeight : 0.f);
3177+
if (z <= destinationFloor + 0.5f) // if is bellow ground or slightly above it, not in air - should hover too
3178+
return false;
3179+
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")
31703180
}
31713181

31723182
void Unit::ProcessPositionDataChanged(PositionFullTerrainStatus const& data)

0 commit comments

Comments
 (0)