I've been struggeling some with my pathing today. I got the loading off of the texture data to work pretty fast, and the base waypoint path object functionality was pretty straight forward, but for some reason the pathwalker component is misbehaving strangely.
Initialization:
current_node = path->getStartNode(); next_node = path->getNextNode(current_node); fullDist = siut::simd::standard::length(next_node->getPos() - current_node->getPos()); go->setPos(current_node->getPos());
Update:
void PathWalker::Update(double dt){ if(pathFinished) return; //Interpolate towards goal position float partDist = siut::simd::standard::length(next_node->getPos() - go->getPos()); std::cout << partDist << std::endl; if(partDist < 0.5f) { std::cout << "Reached node!" << std::endl; current_node = next_node; next_node = path->getNextNode(current_node); fullDist = siut::simd::standard::length(next_node->getPos() - current_node->getPos()); return; } float u = (partDist/fullDist)*(float)dt; //std::cout << "U: " << u << std::endl; siut::simd::Vec3f pos = siut::simd::standard::lerp(current_node->getPos(), next_node->getPos(), u);// - go->getPos(); //go->translate(pos); go->setPos(pos); if(current_node == path->getEndNode()) pathFinished = true;}
The code should be fairly simple, so not sure why I'm failing misserably. It's been a long day, so maybe that's the cause!
Here's the WaypointPath.cpp
void WaypointPath::setStartNode(IPathNode *node){ startNode = node; if(path.empty()) return; if(startNode->getNextNode() == NULL) { startNode->setNextNode(path[0]); path[0]->setPrevNode(startNode); }}void WaypointPath::addNode(IPathNode *node){ IPathNode *prevNode = NULL; if(path.size() > 0) prevNode = path[path.size() - 1]; if(prevNode) { node->setPrevNode(prevNode); prevNode->setNextNode(node); } path.push_back(node); if(startNode) { if(startNode->getNextNode() == NULL) { node->setPrevNode(startNode); startNode->setNextNode(node); } }}IPathNode *WaypointPath::getNextNode(IPathNode *node){ if(node == NULL) node = startNode; if(node == NULL) return NULL; IPathNode *nextNode = node->getNextNode(); if(nextNode) return nextNode; else return endNode;}
I'll probably figure it out tomorrow morning after some sleep though :P