Skip to content

Commit

Permalink
Use center of gameobject model as collision height.
Browse files Browse the repository at this point in the history
  • Loading branch information
ratkosrb committed Nov 16, 2023
1 parent 9cb972d commit d3e7026
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/game/Objects/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2541,6 +2541,14 @@ void GameObject::GetClosestChairSlotPosition(float userX, float userY, float& ou
outY = GetPositionY();
}

float GameObject::GetCollisionHeight() const
{
// use the center of the model
if (GameObjectDisplayInfoAddon const* displayInfo = sGameObjectDisplayInfoAddonStorage.LookupEntry<GameObjectDisplayInfoAddon>(GetDisplayId()))
return (displayInfo->max_z + displayInfo->min_z) * 0.5f * GetObjectScale();
return 1.0f;
}

bool GameObject::IsAtInteractDistance(Position const& pos, float radius) const
{
if (GameObjectDisplayInfoAddon const* displayInfo = sGameObjectDisplayInfoAddonStorage.LookupEntry<GameObjectDisplayInfoAddon>(GetDisplayId()))
Expand Down
1 change: 1 addition & 0 deletions src/game/Objects/GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ class GameObject : public SpellCaster
uint32 GetFactionTemplateId() const final { return GetGOInfo()->faction; }
uint32 GetLevel() const final ;

float GetCollisionHeight() const final;
bool IsAtInteractDistance(Position const& pos, float radius) const;
bool IsAtInteractDistance(Player const* player, uint32 maxRange = 0) const;

Expand Down
6 changes: 3 additions & 3 deletions src/game/Objects/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1617,15 +1617,15 @@ bool WorldObject::IsWithinLOSInMap(WorldObject const* obj, bool checkDynLos) con
return true;
float ox, oy, oz;
obj->GetPosition(ox, oy, oz);
float targetHeight = obj->IsUnit() ? obj->ToUnit()->GetCollisionHeight() : 2.f;
float targetHeight = obj->GetCollisionHeight();
return (IsWithinLOS(ox, oy, oz, checkDynLos, targetHeight));
}

bool WorldObject::IsWithinLOSAtPosition(float ownX, float ownY, float ownZ, float targetX, float targetY, float targetZ, bool checkDynLos, float targetHeight) const
{
if (IsInWorld())
{
float height = IsUnit() ? ToUnit()->GetCollisionHeight() : 2.f;
float height = GetCollisionHeight();
return GetMap()->isInLineOfSight(ownX, ownY, ownZ + height, targetX, targetY, targetZ + targetHeight, checkDynLos);
}

Expand Down Expand Up @@ -2005,7 +2005,7 @@ void WorldObject::MovePositionToFirstCollision(Position& pos, float dist, float

GenericTransport* transport = GetTransport();

float halfHeight = IsUnit() ? static_cast<Unit*>(this)->GetCollisionHeight() : 0.0f;
float halfHeight = GetCollisionHeight();
if (IsUnit())
{
PathFinder path(static_cast<Unit*>(this));
Expand Down
1 change: 1 addition & 0 deletions src/game/Objects/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ class WorldObject : public Object
// angle to face `obj` to `this` using distance includes size of `obj`
GetNearPoint(obj, x, y, z, obj->GetObjectBoundingRadius(), distance2d, GetAngle(obj));
}
virtual float GetCollisionHeight() const { return 1.0f; }
virtual float GetObjectBoundingRadius() const { return DEFAULT_WORLD_OBJECT_SIZE; }
virtual float GetCombatReach() const { return 0.f; }

Expand Down
2 changes: 1 addition & 1 deletion src/game/Objects/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ class Unit : public SpellCaster
void ResetTransformScale();
float GetNativeScale() const;
void SetNativeScale(float scale);
float GetCollisionHeight() const { return m_modelCollisionHeight * m_nativeScaleOverride; }
float GetCollisionHeight() const final { return m_modelCollisionHeight * m_nativeScaleOverride; }
float GetMinSwimDepth() const { return GetCollisionHeight() * 0.75f; } // client switches to swim animation at this depth
static float GetScaleForDisplayId(uint32 displayId);
void UpdateModelData(); // at any changes to scale and/or displayId
Expand Down

0 comments on commit d3e7026

Please sign in to comment.