added finding path with A* and json file to know where character can walk
This commit is contained in:
1 parent
eff7322140
commit
4eaefd25d4
11 files changed
+905
-11
No files matched your search
@@ -233,6 +233,8 @@ namespace ZL
|
||||
npcs.push_back(std::move(npc02));
|
||||
|
||||
std::cout << "Load resurces step 12" << std::endl;
|
||||
|
||||
setupNavigation();
|
||||
|
||||
loadingCompleted = true;
|
||||
|
||||
@@ -279,6 +281,40 @@ namespace ZL
|
||||
}
|
||||
}
|
||||
|
||||
void Game::setupNavigation()
|
||||
{
|
||||
std::vector<PathFinder::ObstacleMesh> obstacles;
|
||||
obstacles.reserve(gameObjects.size() + interactiveObjects.size());
|
||||
|
||||
for (const auto& item : gameObjects) {
|
||||
const LoadedGameObject& gameObj = item.second;
|
||||
obstacles.push_back({ &gameObj.mesh.data, Eigen::Vector3f::Zero() });
|
||||
}
|
||||
|
||||
for (const InteractiveObject& intObj : interactiveObjects) {
|
||||
if (!intObj.isActive) {
|
||||
continue;
|
||||
}
|
||||
obstacles.push_back({ &intObj.mesh.data, intObj.position });
|
||||
}
|
||||
|
||||
navigation.build(obstacles, "resources/config2/navigation.json", CONST_ZIP_FILE);
|
||||
|
||||
auto planner = [this](const Eigen::Vector3f& start, const Eigen::Vector3f& end) {
|
||||
return navigation.findPath(start, end);
|
||||
};
|
||||
|
||||
if (player) {
|
||||
player->setPathPlanner(planner);
|
||||
}
|
||||
|
||||
for (auto& npc : npcs) {
|
||||
if (npc) {
|
||||
npc->setPathPlanner(planner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InteractiveObject* Game::raycastInteractiveObjects(const Eigen::Vector3f& rayOrigin, const Eigen::Vector3f& rayDir) {
|
||||
if (interactiveObjects.empty()) {
|
||||
std::cout << "[RAYCAST] No interactive objects to check" << std::endl;
|
||||
@@ -897,5 +933,10 @@ namespace ZL
|
||||
return dialogueSystem.getFlag(flag);
|
||||
}
|
||||
|
||||
bool Game::setNavigationAreaAvailable(const std::string& areaName, bool available)
|
||||
{
|
||||
return navigation.setAreaAvailable(areaName, available);
|
||||
}
|
||||
|
||||
|
||||
} // namespace ZL
|
||||
Reference in new issue
Block a user