Skip to content

Commit

Permalink
Merge pull request #753 from openmultiplayer/kseny/fix_rot
Browse files Browse the repository at this point in the history
Fix move object rotation when optional args are not set
  • Loading branch information
AmyrAhmady authored Oct 26, 2023
2 parents b425201 + 924d553 commit 2037a95
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions Server/Components/Objects/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,30 @@ class BaseObject : public ObjectType, public PoolIDProvider, public NoCopy
moving_ = true;
moveData_ = data;

/// targetRot being NAN will result in rotSpeed being NAN resulting in no rotation
if (moveData_.targetRot.x == -1000.0f && moveData_.targetRot.y == -1000.0f && moveData_.targetRot.z == -1000.0f)
// Send client current object rotation when passed rotation is smaller than or equal to -1000
if (moveData_.targetRot.x <= -1000.0f)
{
moveData_.targetRot.x = rot_.x;
}

if (moveData_.targetRot.y <= -1000.0f)
{
moveData_.targetRot.y = rot_.y;
}

if (moveData_.targetRot.z <= -1000.0f)
{
moveData_.targetRot.z = rot_.z;
}

float rotDistance = glm::distance(rot_, moveData_.targetRot);
if (rotDistance == 0.0f)
{
rotSpeed_ = NAN;
}
else
{
rotSpeed_ = glm::distance(rot_, moveData_.targetRot) * moveData_.speed / glm::distance(pos_, moveData_.targetPos);
rotSpeed_ = rotDistance * moveData_.speed / glm::distance(pos_, moveData_.targetPos);
}

return makeMovePacket();
Expand Down

0 comments on commit 2037a95

Please sign in to comment.