diff --git a/src/Game.cpp b/src/Game.cpp index 0b8b000..8c76055 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -953,32 +953,34 @@ namespace ZL std::cout << "[CLICK] Player moving to object..." << std::endl; } else { + // Check if we clicked on an NPC Character* clickedNpc = raycastNpcs(camPos, rayDir); if (clickedNpc && player) { float distance = (player->position - clickedNpc->position).norm(); - if (distance <= clickedNpc->interactionRadius) { - int npcIndex = -1; - for (size_t i = 0; i < npcs.size(); ++i) { - if (npcs[i].get() == clickedNpc) { - npcIndex = static_cast(i); - break; - } + int npcIndex = -1; + for (size_t i = 0; i < npcs.size(); ++i) { + if (npcs[i].get() == clickedNpc) { + npcIndex = static_cast(i); + break; } - if (npcIndex != -1) { + } + if (npcIndex != -1) { + if (distance <= clickedNpc->interactionRadius) { std::cout << "[CLICK] *** SUCCESS: Clicked on NPC index: " << npcIndex << " ***" << std::endl; scriptEngine.callNpcInteractCallback(npcIndex); + } + else { + std::cout << "[CLICK] Too far from NPC (distance " << distance + << " > " << clickedNpc->interactionRadius << ")" << std::endl; + } - if (clickedNpc->canAttack) - { - player->attackTarget = clickedNpc; - } + if (clickedNpc->canAttack) + { + player->attackTarget = clickedNpc; } } - else { - std::cout << "[CLICK] Too far from NPC (distance " << distance - << " > " << clickedNpc->interactionRadius << ")" << std::endl; - } + } else if (rayDir.y() < -0.001f && player) { // Otherwise, unproject click to ground plane for Viola's walk target diff --git a/src/items/GameObjectLoader.cpp b/src/items/GameObjectLoader.cpp index b19044b..fb5a9c9 100644 --- a/src/items/GameObjectLoader.cpp +++ b/src/items/GameObjectLoader.cpp @@ -348,9 +348,9 @@ namespace ZL { } try { - if (npcData.animationIdlePath.substr(npcData.animationIdlePath.size() - 5) == ".anim") + if (npcData.animationWalkPath.substr(npcData.animationWalkPath.size() - 5) == ".anim") { - npc->loadBinaryAnimation(AnimationState::WALK, npcData.animationIdlePath, zipPath); + npc->loadBinaryAnimation(AnimationState::WALK, npcData.animationWalkPath, zipPath); } else {