Skip to content

Commit

Permalink
another attempt to fix npc movements
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Apr 24, 2024
1 parent 7af68ca commit aeda9d6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Server/Components/NPCs/NPC/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ bool NPC::move(Vector3 pos, NPCMoveType moveType)

if (!(std::fabs(glm::length(velocity_)) < DBL_EPSILON))
{
estimatedArrivalTimeNS_ = Time::now().time_since_epoch().count() + (static_cast<long long>(distance / glm::length(velocity_)) * ((npcComponent_->getFootSyncRate() * 10000) + 1000000));
estimatedArrivalTimeNS_ = Time::now().time_since_epoch().count() + (static_cast<long long>(distance / glm::length(velocity_)) * (/* (npcComponent_->getFootSyncRate() * 10000) +*/ 1000000));
}
else
{
Expand Down Expand Up @@ -228,10 +228,11 @@ void NPC::advance(TimePoint now)
{
auto position = getPosition();

if (estimatedArrivalTimeNS_ <= Time::now().time_since_epoch().count())
if (estimatedArrivalTimeNS_ <= Time::now().time_since_epoch().count() || glm::distance(position, targetPosition_) <= 0.1f)
{
footSync_.Position = targetPosition_;
auto pos = targetPosition_;
stopMove();
setPosition(pos);
npcComponent_->getEventDispatcher_internal().dispatch(&NPCEventHandler::onNPCFinishMove, *this);
}
else
Expand Down

0 comments on commit aeda9d6

Please sign in to comment.