1
This commit is contained in:
parent
c044148ce3
commit
1d34a4c892
@ -931,5 +931,48 @@ float HeroAgent::GetHPRate()
|
||||
|
||||
behaviac::EBTStatus HeroAgent::CoGetRunAwayPoint()
|
||||
{
|
||||
PRE_ENTER_COROUTINE();
|
||||
if (!current_target_agent->IsValid()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
auto context = MAKE_BTCONTEXT
|
||||
(
|
||||
int try_count = 0;
|
||||
int step_len = 50;
|
||||
);
|
||||
auto co = std::make_shared<BtCoroutine>(context, co_id, "CoGetRunAwayPoint");
|
||||
co->runing_cb =
|
||||
[this, context] ()
|
||||
{
|
||||
if (owner_->dead) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
if (!current_target_agent->IsValid()) {
|
||||
return behaviac::BT_FAILURE;
|
||||
}
|
||||
|
||||
glm::vec3 gas_center = GlmHelper::Vec2ToVec3(owner_->room->GetGasData().pos_new);
|
||||
gas_center.y = owner_->GetPos().ToGlmVec3().y;
|
||||
if (GlmHelper::IsEqual2D(owner_->GetPos().ToGlmVec3(),
|
||||
gas_center)) {
|
||||
out_point0 = gas_center;
|
||||
return behaviac::BT_SUCCESS;
|
||||
}
|
||||
|
||||
glm::vec3 dir = gas_center - owner_->GetPos().ToGlmVec3();
|
||||
GlmHelper::Normalize(dir);
|
||||
|
||||
glm::vec3 center = owner_->GetPos().ToGlmVec3() +
|
||||
dir * (50.0f + (float)(context->try_count + 1) * context->step_len);
|
||||
owner_->room->map_instance->Scale(center);
|
||||
glm::vec3 point;
|
||||
bool ok = owner_->room->map_instance->FindConnectableNearestPoint(center, 50, point);
|
||||
if (ok) {
|
||||
owner_->room->map_instance->UnScale(point);
|
||||
out_point0 = point;
|
||||
return behaviac::BT_SUCCESS;
|
||||
}
|
||||
return behaviac::BT_FAILURE;
|
||||
};
|
||||
return StartCoroutine(co);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user