added npc's gift
This commit is contained in:
1 parent
bc2997d86f
commit
34759326b9
9 files changed
+166
-15
No files matched your search
+50
-11
@@ -305,6 +305,28 @@ namespace ZL
|
||||
|
||||
return closestObject;
|
||||
}
|
||||
|
||||
Character* Game::raycastNpcs(const Eigen::Vector3f& rayOrigin, const Eigen::Vector3f& rayDir, float maxDistance) {
|
||||
Character* closestNpc = nullptr;
|
||||
float closestDist = maxDistance;
|
||||
|
||||
for (auto& npc : npcs) {
|
||||
Eigen::Vector3f toNpc = npc->position - rayOrigin;
|
||||
float distAlongRay = toNpc.dot(rayDir);
|
||||
if (distAlongRay < 0.1f) continue;
|
||||
|
||||
Eigen::Vector3f closestPoint = rayOrigin + rayDir * distAlongRay;
|
||||
float distToNpc = (closestPoint - npc->position).norm();
|
||||
|
||||
float radius = npc->modelScale * 50.0f;
|
||||
|
||||
if (distToNpc <= radius && distAlongRay < closestDist) {
|
||||
closestDist = distAlongRay;
|
||||
closestNpc = npc.get();
|
||||
}
|
||||
}
|
||||
return closestNpc;
|
||||
}
|
||||
|
||||
void Game::drawUI()
|
||||
{
|
||||
@@ -585,24 +607,41 @@ namespace ZL
|
||||
InteractiveObject* clickedObject = raycastInteractiveObjects(camPos, rayDir);
|
||||
if (clickedObject && player && clickedObject->isActive) {
|
||||
std::cout << "[CLICK] *** SUCCESS: Clicked on interactive object: " << clickedObject->name << " ***" << std::endl;
|
||||
std::cout << "[CLICK] Object position: (" << clickedObject->position.x() << ", "
|
||||
std::cout << "[CLICK] Object position: (" << clickedObject->position.x() << ", "
|
||||
<< clickedObject->position.y() << ", " << clickedObject->position.z() << ")" << std::endl;
|
||||
std::cout << "[CLICK] Player position: (" << player->position.x() << ", "
|
||||
std::cout << "[CLICK] Player position: (" << player->position.x() << ", "
|
||||
<< player->position.y() << ", " << player->position.z() << ")" << std::endl;
|
||||
|
||||
|
||||
targetInteractiveObject = clickedObject;
|
||||
player->setTarget(clickedObject->position);
|
||||
std::cout << "[CLICK] Player moving to object..." << std::endl;
|
||||
}
|
||||
else if (rayDir.y() < -0.001f && player) {
|
||||
// Otherwise, unproject click to ground plane for Viola's walk target
|
||||
float t = -camPos.y() / rayDir.y();
|
||||
Eigen::Vector3f hit = camPos + rayDir * t;
|
||||
std::cout << "[CLICK] Clicked on ground at: (" << hit.x() << ", " << hit.z() << ")" << std::endl;
|
||||
player->setTarget(Eigen::Vector3f(hit.x(), 0.f, hit.z()));
|
||||
}
|
||||
else {
|
||||
std::cout << "[CLICK] No valid target found" << std::endl;
|
||||
// Check if we clicked on an NPC
|
||||
Character* clickedNpc = raycastNpcs(camPos, rayDir);
|
||||
if (clickedNpc && player) {
|
||||
int npcIndex = -1;
|
||||
for (size_t i = 0; i < npcs.size(); ++i) {
|
||||
if (npcs[i].get() == clickedNpc) {
|
||||
npcIndex = static_cast<int>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (npcIndex != -1) {
|
||||
std::cout << "[CLICK] *** SUCCESS: Clicked on NPC index: " << npcIndex << " ***" << std::endl;
|
||||
scriptEngine.callNpcInteractCallback(npcIndex);
|
||||
}
|
||||
}
|
||||
else if (rayDir.y() < -0.001f && player) {
|
||||
// Otherwise, unproject click to ground plane for Viola's walk target
|
||||
float t = -camPos.y() / rayDir.y();
|
||||
Eigen::Vector3f hit = camPos + rayDir * t;
|
||||
std::cout << "[CLICK] Clicked on ground at: (" << hit.x() << ", " << hit.z() << ")" << std::endl;
|
||||
player->setTarget(Eigen::Vector3f(hit.x(), 0.f, hit.z()));
|
||||
}
|
||||
else {
|
||||
std::cout << "[CLICK] No valid target found" << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << "========================================\n" << std::endl;
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user