Fixing rotation issues in battle mode
This commit is contained in:
1 parent
984d7489d5
commit
de2e18e38f
4 files changed
+84
-61
No files matched your search
+5
-60
@@ -176,6 +176,7 @@ namespace ZL
|
||||
/*Eigen::Quaternionf(Eigen::AngleAxisf(M_PI, Eigen::Vector3f::UnitZ()));*/
|
||||
|
||||
player->canAttack = true;
|
||||
player->isPlayer = true;
|
||||
std::cout << "Load resurces step 9" << std::endl;
|
||||
|
||||
// Load NPCs from JSON
|
||||
@@ -227,6 +228,7 @@ namespace ZL
|
||||
npc02->position = Eigen::Vector3f(0.f, 0.f, -20.f);
|
||||
npc02->setTarget(npc02->position);
|
||||
npc02->canAttack = true;
|
||||
npc02->attackTarget = player.get();
|
||||
|
||||
npcs.push_back(std::move(npc02));
|
||||
|
||||
@@ -507,64 +509,7 @@ namespace ZL
|
||||
if (player) player->update(delta);
|
||||
for (auto& npc : npcs) npc->update(delta);
|
||||
|
||||
for (auto& npc : npcs)
|
||||
{
|
||||
if (npc->canAttack)
|
||||
{
|
||||
float distToGhost = (player->position - npc->position).norm();
|
||||
if (distToGhost >= 10.f)
|
||||
{
|
||||
if (npc->battle_state != 0)
|
||||
{
|
||||
npc->battle_state = 0;
|
||||
}
|
||||
}
|
||||
else if (distToGhost < 10.0f && distToGhost >= 1.f) {
|
||||
npc->setTarget(player->position);
|
||||
if (npc->battle_state != 0)
|
||||
{
|
||||
npc->battle_state = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
npc->setTarget(npc->position);
|
||||
if (npc->battle_state != 1)
|
||||
{
|
||||
npc->battle_state = 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (playerAttackTarget != nullptr)
|
||||
{
|
||||
auto pos = playerAttackTarget->position;
|
||||
float distToTarget = (player->position - pos).norm();
|
||||
|
||||
if (distToTarget > 1.0)
|
||||
{
|
||||
player->setTarget(Eigen::Vector3f(pos.x(), 0.f, pos.z()));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player->battle_state != 1)
|
||||
{
|
||||
player->setTarget(player->position);
|
||||
player->battle_state = 1;
|
||||
//player->attack = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (playerAttackTarget == nullptr)
|
||||
{
|
||||
if (player->battle_state != 0)
|
||||
{
|
||||
player->battle_state = 0;
|
||||
player->attack = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check if player reached target interactive object
|
||||
if (targetInteractiveObject && player) {
|
||||
@@ -691,7 +636,7 @@ namespace ZL
|
||||
std::cout << "\n========== MOUSE DOWN EVENT ==========" << std::endl;
|
||||
handleDown(ZL::UiManager::MOUSE_FINGER_ID, mx, my);
|
||||
|
||||
playerAttackTarget = nullptr;
|
||||
player->attackTarget = nullptr;
|
||||
|
||||
// Calculate ray for picking
|
||||
if (dialogueSystem.blocksGameplayInput()) {
|
||||
@@ -749,7 +694,7 @@ namespace ZL
|
||||
|
||||
if (clickedNpc->canAttack)
|
||||
{
|
||||
playerAttackTarget = clickedNpc;
|
||||
player->attackTarget = clickedNpc;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user