void Unit::MoveAlongPath(float elapsedSec)
{
	//First check if the unit is near the first position in the path
	Point2f nextCheckPoint = m_Path.front();

	//If the unit passed the checkpoint, set the position to the checkpoint and calculate the direction towards the next checkpoint
	//ELse, move the unit along its direction using the elapsedSec
	if(CheckPassed(nextCheckPoint))
	{
		Vector2f oldDir = m_Direction;

		UpdateFOW();
		m_Path.pop_front();

		while (!m_Path.empty() && !m_pWorld.lock()->GetTileAtPosition(m_Path.front())->GetPassable(m_ObjectType.second, shared_from_this()))
		{
			std::deque toAdd;
			m_Path.pop_front();

			if(!m_Path.empty())
				m_pWorld.lock()->GetPath(m_Position, m_Path.front(), m_ObjectType.second, shared_from_this(), toAdd);

			while (!toAdd.empty())
			{
				m_Path.push_front(toAdd.back());
				toAdd.pop_back();
			}
		}

		//If the path is empty after reaching the position, make the unit stop moving
		//Else set the direction to the new first position in the path
		if (m_ActionState == ActionState::standGround || m_ActionState == ActionState::idle)
		{
			m_Path.clear();
			SetSpriteData(m_ActionState);
			SetSpriteCollumn(m_ActionState);
			m_Position.x = nextCheckPoint.x;
			m_Position.y = nextCheckPoint.y;
		}
		else if (m_Path.empty())
		{
			if (m_ActionState != ActionState::fighting)
			{
				m_ActionState = ActionState::idle;
				SetSpriteData(ActionState::idle);
				SetSpriteCollumn(ActionState::idle);
			}
			m_Position.x = nextCheckPoint.x;
			m_Position.y = nextCheckPoint.y;
		}
		else
		{
			SetDirection();
			SetOccupiedTiles();

			if(m_Direction != oldDir)
				SetSpriteCollumn(ActionState::moving);
		}
	}
	else
	{
		if (m_pWorld.lock()->GetTileAtPosition(m_Path.front()) == m_pOccupiedTiles.front().lock())
			m_Position = (Vector2f(m_Position.x, m_Position.y) +  (m_Direction * m_UnitDetails.movementSpeed * elapsedSec)).ToPoint2f();
	}
}