From 595afe42e5a0764672d5473396a48790a0be2201 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sun, 2 Apr 2023 22:37:24 -0500 Subject: [PATCH 1/5] fix the lookat --- dGame/dBehaviors/ChangeOrientationBehavior.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dGame/dBehaviors/ChangeOrientationBehavior.cpp b/dGame/dBehaviors/ChangeOrientationBehavior.cpp index a60be62f..d07e7429 100644 --- a/dGame/dBehaviors/ChangeOrientationBehavior.cpp +++ b/dGame/dBehaviors/ChangeOrientationBehavior.cpp @@ -16,7 +16,7 @@ void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitS if (self == nullptr || other == nullptr) return; const auto source = self->GetPosition(); - const auto destination = self->GetPosition(); + const auto destination = other->GetPosition(); if (m_OrientCaster) { auto* baseCombatAIComponent = self->GetComponent(); From 1fb086ccbdb146caa4423191fc9e1d57dd996684 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Mon, 3 Apr 2023 08:21:23 -0500 Subject: [PATCH 2/5] Fully implement Change orientation fix bug where you would always look at self added to_angle handline --- .../dBehaviors/ChangeOrientationBehavior.cpp | 57 +++++++++---------- dGame/dBehaviors/ChangeOrientationBehavior.h | 24 +++----- 2 files changed, 35 insertions(+), 46 deletions(-) diff --git a/dGame/dBehaviors/ChangeOrientationBehavior.cpp b/dGame/dBehaviors/ChangeOrientationBehavior.cpp index d07e7429..a7dc838f 100644 --- a/dGame/dBehaviors/ChangeOrientationBehavior.cpp +++ b/dGame/dBehaviors/ChangeOrientationBehavior.cpp @@ -2,43 +2,40 @@ #include "BehaviorBranchContext.h" #include "BehaviorContext.h" #include "EntityManager.h" -#include "BaseCombatAIComponent.h" - -void ChangeOrientationBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) { -} void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) { - if (!m_ToTarget) return; // TODO: Add the other arguments to this behavior + Entity* sourceEntity; + if (this->m_orientCaster) sourceEntity = EntityManager::Instance()->GetEntity(context->originator); + else sourceEntity = EntityManager::Instance()->GetEntity(branch.target); + if (!sourceEntity) return; - auto* self = EntityManager::Instance()->GetEntity(context->originator); - auto* other = EntityManager::Instance()->GetEntity(branch.target); - if (self == nullptr || other == nullptr) return; + if (this->m_toTarget) { + Entity* destinationEntity; + if (this->m_orientCaster) destinationEntity = EntityManager::Instance()->GetEntity(branch.target); + else destinationEntity = EntityManager::Instance()->GetEntity(context->originator); + if (!destinationEntity) return; - const auto source = self->GetPosition(); - const auto destination = other->GetPosition(); - - if (m_OrientCaster) { - auto* baseCombatAIComponent = self->GetComponent(); - - /*if (baseCombatAIComponent != nullptr) - { - baseCombatAIComponent->LookAt(destination); + const auto source = sourceEntity->GetPosition(); + const auto destination = destinationEntity->GetPosition(); + sourceEntity->SetRotation(NiQuaternion::LookAt(source, destination)); + } else if (this->m_toAngle){ + auto baseAngle = NiPoint3(this->m_angle, 0, 0); + if (this->m_relative){ + auto sourceAngle = sourceEntity->GetRotation().GetEulerAngles(); + baseAngle += sourceAngle; } - else*/ - { - self->SetRotation(NiQuaternion::LookAt(source, destination)); - } - - EntityManager::Instance()->SerializeEntity(self); - } else { - other->SetRotation(NiQuaternion::LookAt(destination, source)); - - EntityManager::Instance()->SerializeEntity(other); - } + auto newRotation = NiQuaternion::FromEulerAngles(baseAngle); + sourceEntity->SetRotation(newRotation); + } else return; + EntityManager::Instance()->SerializeEntity(sourceEntity); + return; } void ChangeOrientationBehavior::Load() { - m_OrientCaster = GetBoolean("orient_caster"); - m_ToTarget = GetBoolean("to_target"); + this->m_orientCaster = GetBoolean("orient_caster", true); + this->m_toTarget = GetBoolean("to_target", false); + this->m_toAngle = GetBoolean("to_angle", false); + this->m_angle = GetFloat("angle", 0.0f); + this->m_relative = GetBoolean("relative", false); } diff --git a/dGame/dBehaviors/ChangeOrientationBehavior.h b/dGame/dBehaviors/ChangeOrientationBehavior.h index eb038ffb..46d471ad 100644 --- a/dGame/dBehaviors/ChangeOrientationBehavior.h +++ b/dGame/dBehaviors/ChangeOrientationBehavior.h @@ -1,25 +1,17 @@ #pragma once #include "Behavior.h" - #include -class ChangeOrientationBehavior final : public Behavior -{ +class ChangeOrientationBehavior final : public Behavior { public: - bool m_OrientCaster; - bool m_ToTarget; - - /* - * Inherited - */ - - explicit ChangeOrientationBehavior(const uint32_t behaviorId) : Behavior(behaviorId) { - } - - void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; - + explicit ChangeOrientationBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {} void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; - void Load() override; +private: + bool m_orientCaster; + bool m_toTarget; + bool m_toAngle; + float m_angle; + bool m_relative; }; From a5ff93351dea4e19c0c4121db0c532f22719690a Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Mon, 3 Apr 2023 08:25:47 -0500 Subject: [PATCH 3/5] remove empty line remove undeeded header --- dGame/dBehaviors/ChangeOrientationBehavior.cpp | 1 - dGame/dBehaviors/ChangeOrientationBehavior.h | 1 - 2 files changed, 2 deletions(-) diff --git a/dGame/dBehaviors/ChangeOrientationBehavior.cpp b/dGame/dBehaviors/ChangeOrientationBehavior.cpp index a7dc838f..398e9e33 100644 --- a/dGame/dBehaviors/ChangeOrientationBehavior.cpp +++ b/dGame/dBehaviors/ChangeOrientationBehavior.cpp @@ -9,7 +9,6 @@ void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitS else sourceEntity = EntityManager::Instance()->GetEntity(branch.target); if (!sourceEntity) return; - if (this->m_toTarget) { Entity* destinationEntity; if (this->m_orientCaster) destinationEntity = EntityManager::Instance()->GetEntity(branch.target); diff --git a/dGame/dBehaviors/ChangeOrientationBehavior.h b/dGame/dBehaviors/ChangeOrientationBehavior.h index 46d471ad..22c92bb8 100644 --- a/dGame/dBehaviors/ChangeOrientationBehavior.h +++ b/dGame/dBehaviors/ChangeOrientationBehavior.h @@ -1,7 +1,6 @@ #pragma once #include "Behavior.h" -#include class ChangeOrientationBehavior final : public Behavior { public: From dffcbcd4d4970927a3137dd4ad85c830df9aeb8a Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Mon, 3 Apr 2023 08:29:39 -0500 Subject: [PATCH 4/5] cleanup --- dGame/dBehaviors/ChangeOrientationBehavior.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/dGame/dBehaviors/ChangeOrientationBehavior.cpp b/dGame/dBehaviors/ChangeOrientationBehavior.cpp index 398e9e33..ee9e2009 100644 --- a/dGame/dBehaviors/ChangeOrientationBehavior.cpp +++ b/dGame/dBehaviors/ChangeOrientationBehavior.cpp @@ -15,17 +15,13 @@ void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitS else destinationEntity = EntityManager::Instance()->GetEntity(context->originator); if (!destinationEntity) return; - const auto source = sourceEntity->GetPosition(); - const auto destination = destinationEntity->GetPosition(); - sourceEntity->SetRotation(NiQuaternion::LookAt(source, destination)); + sourceEntity->SetRotation( + NiQuaternion::LookAt(sourceEntity->GetPosition(), destinationEntity->GetPosition()) + ); } else if (this->m_toAngle){ auto baseAngle = NiPoint3(this->m_angle, 0, 0); - if (this->m_relative){ - auto sourceAngle = sourceEntity->GetRotation().GetEulerAngles(); - baseAngle += sourceAngle; - } - auto newRotation = NiQuaternion::FromEulerAngles(baseAngle); - sourceEntity->SetRotation(newRotation); + if (this->m_relative) baseAngle += sourceEntity->GetRotation().GetEulerAngles(); + sourceEntity->SetRotation(NiQuaternion::FromEulerAngles(baseAngle)); } else return; EntityManager::Instance()->SerializeEntity(sourceEntity); return; From 930735860b05a23bee25eb7f78946546359ad7be Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Mon, 3 Apr 2023 13:10:51 -0500 Subject: [PATCH 5/5] use z axis --- dGame/dBehaviors/ChangeOrientationBehavior.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dGame/dBehaviors/ChangeOrientationBehavior.cpp b/dGame/dBehaviors/ChangeOrientationBehavior.cpp index ee9e2009..36a2e6a8 100644 --- a/dGame/dBehaviors/ChangeOrientationBehavior.cpp +++ b/dGame/dBehaviors/ChangeOrientationBehavior.cpp @@ -19,8 +19,8 @@ void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitS NiQuaternion::LookAt(sourceEntity->GetPosition(), destinationEntity->GetPosition()) ); } else if (this->m_toAngle){ - auto baseAngle = NiPoint3(this->m_angle, 0, 0); - if (this->m_relative) baseAngle += sourceEntity->GetRotation().GetEulerAngles(); + auto baseAngle = NiPoint3(0, 0, this->m_angle); + if (this->m_relative) baseAngle += sourceEntity->GetRotation().GetForwardVector(); sourceEntity->SetRotation(NiQuaternion::FromEulerAngles(baseAngle)); } else return; EntityManager::Instance()->SerializeEntity(sourceEntity);