Hi everyone, I came here to ask for your help. With my team we are working in a 2D top down game and we are using MoreMountains TopDownEngine for that TopDownEngine official page.
Where is our problem? Well, with the movement system that TopDownEngine implements. Basically the plugin uses a “MovementDirection” to move the characters (player and enemies), so to make the typical AI that follows the player using the A* Pathfinding Project we calculate the direction between the enemy position and the next node to reach.
public virtual void MoveToDestination()
{
if (_path == null)
{
return;
}
if (_currentWaypoint >= _path.vectorPath.Count && !_reachedEndOfPath)
{
_reachedEndOfPath = true;
if (OnMove != null)
{
OnMove();
}
StartPath();
_currentWaypoint = 0;
return;
}
else
{
_reachedEndOfPath = false;
}
Vector2 newDirection = (_path.vectorPath[_currentWaypoint] - OriginPoint).normalized;
float distance = (OriginPoint - _path.vectorPath[_currentWaypoint]).sqrMagnitude;
_characterMovement.SetMovement(newDirection);
if (_characterController.IsForcingToLookAtObject)
{
_characterController.StopForcingToLookAtObject();
}
if (distance < _nextWaypointSquaredDistance)
{
_currentWaypoint++;
}
}
But now we need to implement the Local Avoidance to prevent enemies from accumulating at a single point when they follow the player, but we don’t know how to obtain the direction and give it to the CharacterMovement componen as we did on the previous function.
Vector2 newDirection = (_path.vectorPath[_currentWaypoint] - OriginPoint).normalized;
_characterMovement.SetMovement(newDirection);
The idea is not to break the TopDownEngine movement logic, is there any way to obtain the same direction but using Local Avoidance?