This commit is contained in:
aozhiwei 2023-03-24 17:21:40 +08:00
parent 490491df00
commit 90b3684bf8
3 changed files with 20 additions and 9 deletions

View File

@ -15,16 +15,20 @@ void ReverseBuff::Activate()
{
hold_param1_ = meta->GetBuffParam1(this);
if (caster_.Get()) {
glm::vec3 dir = caster_.Get()->GetPos().CalcDir(owner->GetPos());
if ((std::isfinite(dir.x) &&
std::isfinite(dir.z))) {
dir = dir * 1.0f;
GlmHelper::Normalize(dir);
owner->SetMoveDir(dir);
owner->SetAttackDir(dir);
if (hold_param1_ > 0.001) {
owner->ForwardMove(hold_param1_);
if (!GlmHelper::IsEqual2D(caster_.Get()->GetPos().ToGlmVec3(),
owner->GetPos().ToGlmVec3())) {
glm::vec3 dir = caster_.Get()->GetPos().CalcDir(owner->GetPos());
if ((std::isfinite(dir.x) &&
std::isfinite(dir.z))) {
dir = dir * 1.0f;
GlmHelper::Normalize(dir);
owner->SetMoveDir(dir);
owner->SetAttackDir(dir);
if (hold_param1_ > 0.001) {
owner->ForwardMove(hold_param1_);
}
}
}
}
}

View File

@ -71,3 +71,8 @@ void GlmHelper::FillVert(const glm::vec3& v, float* vert)
vert[1] = v.y;
vert[2] = v.z;
}
bool GlmHelper::IsEqual2D(const glm::vec3& v1, const glm::vec3& v2)
{
return std::abs(v1.x - v2.x) > 0.00001f || std::abs(v1.z - v2.z) > 0.00001f;
}

View File

@ -13,6 +13,8 @@ class GlmHelper
static float Norm(const glm::vec3& v);
static bool IsZero(const glm::vec3& v);
static bool IsEqual2D(const glm::vec3& v1, const glm::vec3& v2);
static float CalcAngle(const glm::vec3& v1, const glm::vec3& v2);
static void FillVert(const glm::vec3& v, float* vert);