This commit is contained in:
aozhiwei 2022-12-14 18:52:21 +08:00
parent d820668b49
commit 8f2bfd1a15

View File

@ -17,43 +17,18 @@ MoveHelper::MoveHelper(Creature* owner)
bool MoveHelper::GetMovePosition(glm::vec3& out_pos) bool MoveHelper::GetMovePosition(glm::vec3& out_pos)
{ {
// 999 if (path_index_ >= paths_.size()) {
#if 1 ClearPath();
#else return false;
Creature* c = owner_; }
if (path_index_ < paths_.size()) { MovePathPoint& curr_point = paths_[path_index_];
a8::Vec2 src_pos; owner_->SetPos(curr_point.curr_pos);
a8::Vec2 tar_pos; if (owner_->GetPos().Distance2D2(curr_point.src_pos) - curr_point.distance >= 0.0001f) {
a8::Vec2 curr_pos; owner_->SetPos(curr_point.tar_pos);
a8::Vec2 dir;
auto& point = paths_[path_index_];
src_pos.x = point.src_pos.x;
src_pos.y = point.src_pos.z;
curr_pos.x = point.curr_pos.x;
curr_pos.y = point.curr_pos.z;
tar_pos.x = point.tar_pos.x;
tar_pos.y = point.tar_pos.z;
dir.x = point.dir.x;
dir.y = point.dir.z;
curr_pos = (curr_pos + dir * owner_->GetSpeed() * 1);
point.curr_pos.x = curr_pos.x;
point.curr_pos.z = curr_pos.y;
owner_->SetPos(curr_pos);
if (owner_->GetPos().Distance(src_pos) - point.distance >= 0.0001f) {
owner_->SetPos(tar_pos);
++path_index_; ++path_index_;
if (path_index_ < paths_.size()) { if (path_index_ < paths_.size()) {
auto& next_point = paths_[path_index_]; MovePathPoint& next_point = paths_[path_index_];
a8::Vec2 dir = owner_->GetPos().CalcDir2D(next_point.tar_pos);
a8::Vec2 v2;
v2.x = next_point.tar_pos.x;
v2.y = next_point.tar_pos.z;
a8::Vec2 dir = (v2 - owner_->GetPos());
dir.Normalize(); dir.Normalize();
next_point.dir.x = dir.x; next_point.dir.x = dir.x;
next_point.dir.z = dir.y; next_point.dir.z = dir.y;
@ -64,11 +39,6 @@ bool MoveHelper::GetMovePosition(glm::vec3& out_pos)
abort(); abort();
} }
return true; return true;
} else {
ClearPath();
}
#endif
return false;
} }
void MoveHelper::CalcTargetPos(float distance) void MoveHelper::CalcTargetPos(float distance)