1
This commit is contained in:
parent
609ae95ad1
commit
c64cdb2f3f
@ -148,8 +148,9 @@ void Human::FindPath()
|
||||
{
|
||||
Vector2D old_pos = pos;
|
||||
{
|
||||
float dot = Vector2D::UP.Dot(move_dir);
|
||||
if (std::abs(dot) <= 0.001f) { //相互垂直
|
||||
float up_dot = Vector2D::UP.Dot(move_dir);
|
||||
bool at_left_side = Vector2D::LEFT.Dot(move_dir) > 0.0001f;
|
||||
if (std::abs(up_dot) <= 0.001f) { //相互垂直
|
||||
//向上
|
||||
pos = old_pos + Vector2D::UP;
|
||||
if (!IsCollision()) {
|
||||
@ -161,9 +162,8 @@ void Human::FindPath()
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (dot > 0.001f) { //基本相同
|
||||
//向右
|
||||
pos = old_pos + Vector2D::RIGHT;
|
||||
} else if (up_dot > 0.001f) { //基本相同
|
||||
pos = old_pos + (at_left_side ? Vector2D::LEFT : Vector2D::RIGHT);
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
} else {
|
||||
@ -173,37 +173,8 @@ void Human::FindPath()
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (dot < 0.001f) { //基本相反
|
||||
//向右
|
||||
pos = old_pos + Vector2D::RIGHT;
|
||||
if (IsCollision()) {
|
||||
//向下
|
||||
pos = old_pos + Vector2D::DOWN;
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
float dot = Vector2D::DOWN.Dot(move_dir);
|
||||
if (std::abs(dot) <= 0.001f) { //相互垂直
|
||||
//向下
|
||||
pos = old_pos + Vector2D::DOWN;
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
} else {
|
||||
//向上
|
||||
pos = old_pos + Vector2D::UP;
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (dot > 0.001f) { //基本相同
|
||||
//向左
|
||||
pos = old_pos + Vector2D::LEFT;
|
||||
} else if (up_dot < 0.001f) { //基本相反
|
||||
pos = old_pos + (at_left_side ? Vector2D::LEFT : Vector2D::RIGHT);
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
} else {
|
||||
@ -213,18 +184,7 @@ void Human::FindPath()
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (dot < 0.001f) { //基本相反
|
||||
//向左
|
||||
pos = old_pos + Vector2D::LEFT;
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
} else {
|
||||
//向上
|
||||
pos = old_pos + Vector2D::UP;
|
||||
if (!IsCollision()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pos = old_pos;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user