1
0
forked from 0ad/0ad

UnitMotion - account for target's movement in ComputeTargetPosition (improve chasing behaviour).

After the recent UM changes, units sometimes chase/flee forever as they
can never actually get in range.
This is because moving to the current target's position is not enough
when the target is moving.

By accounting for the target movement's in ComputeTargetPosition, the
behaviour is much improved.

Differential Revision: https://code.wildfiregames.com/D1987
This was SVN commit r22431.
This commit is contained in:
wraitii 2019-07-03 18:09:31 +00:00
parent 58018a1056
commit 99a341f379

View File

@ -1065,7 +1065,17 @@ bool CCmpUnitMotion::ComputeTargetPosition(CFixedVector2D& out) const
out = cmpPosition->GetPosition2D() + offset;
}
else
{
out = cmpPosition->GetPosition2D();
// If the target is moving, we might never get in range if we just try to reach its current position,
// so we have to try and move to a position where we will be in-range, including their movement.
// Since we request paths asynchronously a the end of our turn, we need to account for twice the movement speed.
// TODO: be cleverer about this. It fixes fleeing nicely currently, but orthogonal movement should be considered,
// and the overall logic could be improved upon.
CmpPtr<ICmpUnitMotion> cmpUnitMotion(GetSimContext(), m_MoveRequest.m_Entity);
if (cmpUnitMotion && cmpUnitMotion->IsMoving())
out += (out - cmpPosition->GetPreviousPosition2D()) * 2;
}
return true;
}