1
This commit is contained in:
parent
6a992aa936
commit
f7403c0b0a
@ -2912,10 +2912,8 @@ void Creature::ShortFindPath()
|
|||||||
if (std::abs(GetMoveDir().x) > FLT_EPSILON ||
|
if (std::abs(GetMoveDir().x) > FLT_EPSILON ||
|
||||||
std::abs(GetMoveDir().z) > FLT_EPSILON
|
std::abs(GetMoveDir().z) > FLT_EPSILON
|
||||||
) {
|
) {
|
||||||
#if 1
|
|
||||||
auto try_move =
|
auto try_move =
|
||||||
[this] (glm::vec3 start, glm::vec3 end,
|
[this] (glm::vec3 start, glm::vec3 end, glm::vec3& new_point) -> bool
|
||||||
glm::vec3& new_point, float& distance) -> bool
|
|
||||||
{
|
{
|
||||||
room->map_instance->Scale(start);
|
room->map_instance->Scale(start);
|
||||||
room->map_instance->Scale(end);
|
room->map_instance->Scale(end);
|
||||||
@ -2926,8 +2924,6 @@ void Creature::ShortFindPath()
|
|||||||
if (ret) {
|
if (ret) {
|
||||||
new_point = hit_point;
|
new_point = hit_point;
|
||||||
room->map_instance->Scale(new_point);
|
room->map_instance->Scale(new_point);
|
||||||
//room->map_instance->Scale(pre_point);
|
|
||||||
//distance = GlmHelper::Norm(pre_point - new_point);
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -2939,67 +2935,10 @@ void Creature::ShortFindPath()
|
|||||||
glm::vec3 move_dir = GetMoveDir();
|
glm::vec3 move_dir = GetMoveDir();
|
||||||
GlmHelper::RotateY(move_dir, angle);
|
GlmHelper::RotateY(move_dir, angle);
|
||||||
glm::vec3 end_pos = start_pos + move_dir * 80.0f;
|
glm::vec3 end_pos = start_pos + move_dir * 80.0f;
|
||||||
|
|
||||||
|
glm::vec3 new_point = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
|
bool ret = try_move(start_pos, end_pos, new_point);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
auto try_move =
|
|
||||||
[this] (glm::vec3& new_move_dir, bool& block, glm::vec3& new_point, float& distance)
|
|
||||||
{
|
|
||||||
glm::vec3 start = GetPos().ToGlmVec3() - GetMoveDir() * -1.0f * 2.0f;
|
|
||||||
glm::vec3 end = start + new_move_dir * 2.0f;
|
|
||||||
glm::vec3 hit_point;
|
|
||||||
bool hit_result = false;
|
|
||||||
|
|
||||||
room->map_instance->Scale(start);
|
|
||||||
room->map_instance->Scale(end);
|
|
||||||
|
|
||||||
bool ret = room->map_instance->Raycast(start, end, hit_point, hit_result);
|
|
||||||
if (ret) {
|
|
||||||
start = GetPos().ToGlmVec3() - GetMoveDir();
|
|
||||||
end = start + new_move_dir * 100.0f;
|
|
||||||
room->map_instance->Scale(start);
|
|
||||||
room->map_instance->Scale(end);
|
|
||||||
|
|
||||||
glm::vec3 pre_point = hit_point;
|
|
||||||
ret = room->map_instance->Raycast(start, end, hit_point, hit_result);
|
|
||||||
if (ret) {
|
|
||||||
new_point = hit_point;
|
|
||||||
room->map_instance->Scale(new_point);
|
|
||||||
room->map_instance->Scale(pre_point);
|
|
||||||
distance = GlmHelper::Norm(pre_point - new_point);
|
|
||||||
} else {
|
|
||||||
block = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
block = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
glm::vec3 new_move_dir = GetMoveDir();
|
|
||||||
GlmHelper::RotateY(new_move_dir, 90 / 180.0f);
|
|
||||||
bool right_block = false;
|
|
||||||
glm::vec3 right_new_point = glm::vec3(0.0f, 0.0f, 0.0f);
|
|
||||||
float right_distance = 0.0f;
|
|
||||||
try_move(new_move_dir, right_block, right_new_point, right_distance);
|
|
||||||
|
|
||||||
new_move_dir = GetMoveDir();
|
|
||||||
GlmHelper::RotateY(new_move_dir, -90 / 180.0f);
|
|
||||||
|
|
||||||
bool left_block = false;
|
|
||||||
glm::vec3 left_new_point = glm::vec3(0.0f, 0.0f, 0.0f);
|
|
||||||
float left_distance = 0.0f;
|
|
||||||
try_move(new_move_dir, left_block, left_new_point, left_distance);
|
|
||||||
|
|
||||||
if (right_block && !left_block) {
|
|
||||||
GetMutablePos().FromGlmVec3(right_new_point);
|
|
||||||
} else if (!right_block && left_block) {
|
|
||||||
GetMutablePos().FromGlmVec3(left_new_point);
|
|
||||||
} else if (right_block && left_block){
|
|
||||||
if (right_distance > left_distance) {
|
|
||||||
GetMutablePos().FromGlmVec3(right_new_point);
|
|
||||||
} else {
|
|
||||||
GetMutablePos().FromGlmVec3(left_new_point);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user