Ejemplo n.º 1
0
void cocos2d::NavMeshAgent::onEnter()
{
    if (_agentID != -1) return;
    Component::onEnter();
    auto scene = _owner->getScene();
    if (scene && scene->getNavMesh()){
        scene->getNavMesh()->addNavMeshAgent(this);
    }
}
Ejemplo n.º 2
0
bool AIPlayer::setPathDestination(const Point3F &pos)
{
   // Pathfinding only happens on the server.
   if(!isServerObject())
      return false;

   if(!getNavMesh())
      updateNavMesh();
   // If we can't find a mesh, just move regularly.
   if(!getNavMesh())
   {
      //setMoveDestination(pos);
      throwCallback("onPathFailed");
      return false;
   }

   // Create a new path.
   NavPath *path = new NavPath();

   path->mMesh = getNavMesh();
   path->mFrom = getPosition();
   path->mTo = pos;
   path->mFromSet = path->mToSet = true;
   path->mAlwaysRender = true;
   path->mLinkTypes = mLinkTypes;
   path->mXray = true;
   // Paths plan automatically upon being registered.
   if(!path->registerObject())
   {
      delete path;
      return false;
   }

   if(path->success())
   {
      // Clear any current path we might have.
      clearPath();
      clearCover();
      clearFollow();
      // Store new path.
      mPathData.path = path;
      mPathData.owned = true;
      // Skip node 0, which we are currently standing on.
      moveToNode(1);
      throwCallback("onPathSuccess");
      return true;
   }
   else
   {
      // Just move normally if we can't path.
      //setMoveDestination(pos, true);
      //return;
      throwCallback("onPathFailed");
      path->deleteObject();
      return false;
   }
}
Ejemplo n.º 3
0
void cocos2d::NavMeshAgent::onExit()
{
    if (_agentID == -1) return;
    Component::onExit();

    auto scene = _owner->getScene();
    if (scene && scene->getNavMesh()){
        scene->getNavMesh()->removeNavMeshAgent(this);
    }
}
Ejemplo n.º 4
0
 OutputIterator findPath(const osg::Vec3f& agentHalfExtents, const osg::Vec3f& start,
     const osg::Vec3f& end, const Flags includeFlags, OutputIterator out) const
 {
     static_assert(
         std::is_same<
             typename std::iterator_traits<OutputIterator>::iterator_category,
             std::output_iterator_tag
         >::value,
         "out is not an OutputIterator"
     );
     const auto navMesh = getNavMesh(agentHalfExtents);
     if (!navMesh)
         return out;
     const auto settings = getSettings();
     return findSmoothPath(navMesh.lock()->getValue(), toNavMeshCoordinates(settings, agentHalfExtents),
         toNavMeshCoordinates(settings, start), toNavMeshCoordinates(settings, end), includeFlags,
         settings, out);
 }