Fully implement Change orientation

fix bug where you would always look at self
added to_angle handline
This commit is contained in:
Aaron Kimbre 2023-04-03 08:21:23 -05:00
parent 595afe42e5
commit 1fb086ccbd
2 changed files with 35 additions and 46 deletions

View File

@ -2,43 +2,40 @@
#include "BehaviorBranchContext.h" #include "BehaviorBranchContext.h"
#include "BehaviorContext.h" #include "BehaviorContext.h"
#include "EntityManager.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) { 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 source = sourceEntity->GetPosition();
const auto destination = other->GetPosition(); const auto destination = destinationEntity->GetPosition();
sourceEntity->SetRotation(NiQuaternion::LookAt(source, destination));
if (m_OrientCaster) { } else if (this->m_toAngle){
auto* baseCombatAIComponent = self->GetComponent<BaseCombatAIComponent>(); auto baseAngle = NiPoint3(this->m_angle, 0, 0);
if (this->m_relative){
/*if (baseCombatAIComponent != nullptr) auto sourceAngle = sourceEntity->GetRotation().GetEulerAngles();
{ baseAngle += sourceAngle;
baseCombatAIComponent->LookAt(destination);
} }
else*/ auto newRotation = NiQuaternion::FromEulerAngles(baseAngle);
{ sourceEntity->SetRotation(newRotation);
self->SetRotation(NiQuaternion::LookAt(source, destination)); } else return;
} EntityManager::Instance()->SerializeEntity(sourceEntity);
return;
EntityManager::Instance()->SerializeEntity(self);
} else {
other->SetRotation(NiQuaternion::LookAt(destination, source));
EntityManager::Instance()->SerializeEntity(other);
}
} }
void ChangeOrientationBehavior::Load() { void ChangeOrientationBehavior::Load() {
m_OrientCaster = GetBoolean("orient_caster"); this->m_orientCaster = GetBoolean("orient_caster", true);
m_ToTarget = GetBoolean("to_target"); 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);
} }

View File

@ -1,25 +1,17 @@
#pragma once #pragma once
#include "Behavior.h" #include "Behavior.h"
#include <vector> #include <vector>
class ChangeOrientationBehavior final : public Behavior class ChangeOrientationBehavior final : public Behavior {
{
public: public:
bool m_OrientCaster; explicit ChangeOrientationBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {}
bool m_ToTarget;
/*
* Inherited
*/
explicit ChangeOrientationBehavior(const uint32_t behaviorId) : Behavior(behaviorId) {
}
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; void Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
void Load() override; void Load() override;
private:
bool m_orientCaster;
bool m_toTarget;
bool m_toAngle;
float m_angle;
bool m_relative;
}; };