Collision check in movement

This commit is contained in:
Yunfan Li
2024-08-12 11:52:33 +08:00
parent d3b1041719
commit 2b35aeb049
2 changed files with 9 additions and 4 deletions

View File

@@ -95,7 +95,7 @@ bool MoveToRpgTargetAction::Execute(Event event)
x += cos(angle) * INTERACTION_DISTANCE * distance;
y += sin(angle) * INTERACTION_DISTANCE * distance;
if (!wo->GetMap()->CheckCollisionAndGetValidCoords(wo, wo->GetPositionX(), wo->GetPositionY(), wo->GetPositionZ(),
x, y, z, false))
x, y, z))
{
x = wo->GetPositionX();
y = wo->GetPositionY();

View File

@@ -820,7 +820,7 @@ bool MovementAction::ReachCombatTo(Unit* target, float distance)
tx += targetMoveDist * cos(target->GetOrientation());
ty += targetMoveDist * sin(target->GetOrientation());
if (!target->GetMap()->CheckCollisionAndGetValidCoords(target, target->GetPositionX(), target->GetPositionY(),
target->GetPositionZ(), tx, ty, tz, false))
target->GetPositionZ(), tx, ty, tz))
{
// disable prediction if position is invalid
tx = target->GetPositionX();
@@ -2357,10 +2357,15 @@ bool MoveRandomAction::Execute(Event event)
float angle = (float)rand_norm() * static_cast<float>(M_PI);
x += urand(0, distance) * cos(angle);
y += urand(0, distance) * sin(angle);
float ox = x;
float oy = y;
float oz = z;
if (!bot->GetMap()->CheckCollisionAndGetValidCoords(bot, bot->GetPositionX(), bot->GetPositionY(),
bot->GetPositionZ(), x, y, z, false))
bot->GetPositionZ(), x, y, z))
{
continue;
x = ox;
y = oy;
z = oz;
}
if (map->IsInWater(bot->GetPhaseMask(), x, y, z, bot->GetCollisionHeight()))
continue;