This commit is contained in:
aozhiwei 2022-11-30 15:59:14 +08:00
parent 4e87a28977
commit 0db1c211fd
5 changed files with 55 additions and 11 deletions

View File

@ -175,6 +175,7 @@ void AndroidAI::ChangeToStateOldAI(AndroidState_e to_state)
move_dir.Rotate(a8::RandAngle());
move_dir.Normalize();
hum->SetMoveDir(move_dir);
hum->GetMoveHelper()->CalcTargetPos(500);
hum->SetAttackDir(hum->GetMoveDir());
}
break;
@ -544,6 +545,7 @@ void AndroidAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
move_dir.Rotate(a8::RandAngle());
move_dir.Normalize();
hum->SetMoveDir(move_dir);
hum->GetMoveHelper()->CalcTargetPos(500);
hum->SetAttackDir(hum->GetMoveDir());
if (node_->param1 <= 1) {
moving_ = false;
@ -557,6 +559,7 @@ void AndroidAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
a8::Vec2 move_dir = node_->target.Get()->GetPos() - hum->GetPos();
move_dir.Normalize();
hum->SetMoveDir(move_dir);
hum->GetMoveHelper()->CalcTargetPos(500);
hum->SetAttackDir(hum->GetMoveDir());
}
}

View File

@ -241,6 +241,7 @@ void HeroAI::UpdatePursuit()
if (distance > 10) {
move_dir.Normalize();
myself->SetMoveDir(move_dir);
myself->GetMoveHelper()->CalcTargetPos(500);
myself->SetAttackDir(myself->GetMoveDir());
}
}
@ -293,6 +294,7 @@ void HeroAI::DoMoveAI()
//if (hero->room->GetFrameNo() - node_->last_adjust_dir_frameno > SERVER_FRAME_RATE * 3) {
a8::Vec2 dir = hero->GetPos() - hero->room->GetGasData().pos_new;
hero->SetMoveDir(dir);
hero->GetMoveHelper()->CalcTargetPos(500);
node_->last_adjust_dir_frameno = hero->room->GetFrameNo();
//}
#endif
@ -359,6 +361,7 @@ void HeroAI::ChangeToStateAI(HeroState_e to_state)
}
hero->SetMoveDir(move_dir);
hero->GetMoveHelper()->CalcTargetPos(500);
hero->SetAttackDir(hero->GetMoveDir());
if (node_->param1 <= 1) {
moving_ = false;
@ -372,6 +375,7 @@ void HeroAI::ChangeToStateAI(HeroState_e to_state)
a8::Vec2 move_dir = node_->target.Get()->GetPos() - hero->GetPos();
move_dir.Normalize();
hero->SetMoveDir(move_dir);
hero->GetMoveHelper()->CalcTargetPos(500);
hero->SetAttackDir(hero->GetMoveDir());
}
}
@ -387,6 +391,7 @@ void HeroAI::ChangeToStateAI(HeroState_e to_state)
a8::Vec2 move_dir = target_pos - hero->GetPos();
move_dir.Normalize();
hero->SetMoveDir(move_dir);
hero->GetMoveHelper()->CalcTargetPos(500);
hero->SetAttackDir(hero->GetMoveDir());
node_->target_pos = target_pos;
}
@ -398,6 +403,7 @@ void HeroAI::ChangeToStateAI(HeroState_e to_state)
a8::Vec2 move_dir = node_->target_obstacle.Get()->GetPos() - hero->GetPos();
move_dir.Normalize();
hero->SetMoveDir(move_dir);
hero->GetMoveHelper()->CalcTargetPos(500);
hero->SetAttackDir(hero->GetMoveDir());
}
break;
@ -550,6 +556,7 @@ void HeroAI::UpdateSweepMine()
a8::Vec2 move_dir = node_->target_obstacle.Get()->GetPos() - myself->GetPos();
move_dir.Normalize();
myself->SetMoveDir(move_dir);
myself->GetMoveHelper()->CalcTargetPos(500);
myself->SetAttackDir(myself->GetMoveDir());
}
float distance = myself->GetPos().Distance(node_->target_obstacle.Get()->GetPos());

View File

@ -2025,14 +2025,14 @@ void Human::_UpdateMove(int speed)
a8::Vec2 new_pos;
new_pos.x = out_pos.x;
new_pos.y = out_pos.z;
SetPos(new_pos);
//SetPos(new_pos);
} else {
GetMoveHelper()->CalcTargetPos(500);
if (GetMoveHelper()->GetMovePosition(out_pos)) {
a8::Vec2 new_pos;
new_pos.x = out_pos.x;
new_pos.y = out_pos.z;
SetPos(new_pos);
//SetPos(new_pos);
}
}
CheckSpecObject();

View File

@ -156,19 +156,20 @@ void MapInstance::Init()
navmesh_query_->init(navmesh_, 1024);
dtTileRef tile_ref = navmesh_->getTileRefAt(0, 0, 0);
int i = 0;
glm::vec3 start;
glm::vec3 end;
glm::vec3 hit_point;
start.x = 10;
//start.y = 0.166666701;
start.x = 141.014694213867;
start.y = 0.0;
start.z = 10;
start.z = 90.133338928223;
end = start;
end.x = 2000;
end.z = 2000;
end.x = 141.014694213867;
end.y = 0;
end.z = 140.133331298828;
auto a = Raycast(0, start, end, hit_point);
int i = 0;
}
#endif
}

View File

@ -14,6 +14,10 @@ MoveHelper::MoveHelper(class MoveableEntity* owner)
bool MoveHelper::GetMovePosition(glm::vec3& out_pos)
{
Creature* c = (Creature*)owner_;
if (!c->IsPlayer()) {
return false;
}
if (path_index_ < paths_.size()) {
a8::Vec2 src_pos;
a8::Vec2 tar_pos;
@ -30,7 +34,7 @@ bool MoveHelper::GetMovePosition(glm::vec3& out_pos)
dir.y = point.dir.z;
owner_->SetPos(src_pos + dir * owner_->GetSpeed() * (owner_->room->GetFrameNo() - point.frameno));
if (owner_->GetPos().Distance(src_pos) - point.distance >= 0.0001) {
if (owner_->GetPos().Distance(src_pos) - point.distance >= 0.0001f) {
owner_->SetPos(tar_pos);
++path_index_;
if (path_index_ < paths_.size()) {
@ -53,6 +57,10 @@ bool MoveHelper::GetMovePosition(glm::vec3& out_pos)
void MoveHelper::CalcTargetPos(float distance)
{
Creature* c = (Creature*)owner_;
if (!c->IsPlayer()) {
return;
}
path_index_ = 0;
paths_.clear();
@ -61,14 +69,20 @@ void MoveHelper::CalcTargetPos(float distance)
glm::vec3 hit_point;
start.x = owner_->GetPos().x / 10.0f;
start.y = 0;
start.z = owner_->GetPos().y / 10.0f;
a8::Vec2 target_pos2d = owner_->GetPos() + owner_->GetMoveDir() * distance;
end.x = target_pos2d.x / 10.0f;
end.y = 0;
end.z = target_pos2d.y / 10.0f;
#ifdef DEBUG
a8::XPrintf("start:%f,%f,%f end:%f,%f,%f\n", {start.x, start.y, start.z, end.x, end.y, end.z});
#endif
bool is_hit = false;
MovePathPoint point;
Creature* c = (Creature*)owner_;
if (c->HasBuffEffect(kBET_ThroughWall) ||
c->HasBuffEffect(kBET_Fly)) {
point.tar_pos = end * 10.f;
@ -86,7 +100,8 @@ void MoveHelper::CalcTargetPos(float distance)
}
} else {
int ret = owner_->room->map_instance->Raycast(0, start, end, hit_point);
if (ret > 1) {
if (ret > 0) {
is_hit = true;
point.tar_pos = hit_point * 10.f;
} else {
point.tar_pos = end * 10.f;
@ -104,5 +119,23 @@ void MoveHelper::CalcTargetPos(float distance)
point.dir.x = dir.x;
point.dir.z = dir.y;
#ifdef DEBUG
a8::XPrintf("CalcTargetPos src_pos:%f,%f tar_pos:%f,%f is_hit:%d start:%f,%f,%f end:%f,%f,%f\n",
{
point.src_pos.x,
point.src_pos.z,
point.tar_pos.x,
point.tar_pos.z,
is_hit ? 1 : 0,
start.x,
start.y,
start.z,
end.x,
end.y,
end.z
});
#endif
paths_.push_back(point);
}