1
This commit is contained in:
parent
dce947c61f
commit
a22c9814c9
@ -2910,18 +2910,63 @@ void Creature::ShotFindPath()
|
|||||||
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
|
||||||
) {
|
) {
|
||||||
|
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();
|
glm::vec3 new_move_dir = GetMoveDir();
|
||||||
GlmHelper::RotateY(new_move_dir, 90 / 180.0f);
|
GlmHelper::RotateY(new_move_dir, 90 / 180.0f);
|
||||||
{
|
bool right_block = false;
|
||||||
glm::vec3 start = GetPos().ToGlmVec3() - GetMoveDir() * -1.0f * 2.0f;
|
glm::vec3 right_new_point = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||||
glm::vec3 end = start + new_move_dir * 1.0f;
|
float right_distance = 0.0f;
|
||||||
glm::vec3 hit_point;
|
try_move(new_move_dir, right_block, right_new_point, right_distance);
|
||||||
bool hit_result;
|
|
||||||
|
|
||||||
room->map_instance->Scale(start);
|
new_move_dir = GetMoveDir();
|
||||||
room->map_instance->Scale(end);
|
GlmHelper::RotateY(new_move_dir, -90 / 180.0f);
|
||||||
|
|
||||||
room->map_instance->Raycast(start, end, hit_point, hit_result);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user