Пример #1
0
    public override void Movement()
    {
        Rotation();

        if (Vector2.Distance(transform.position, playerOffset.position) <= viewDistance.TotalValue && path.Count <= 0)
        {
            path = ASTAR.FindPath(Vector2Int.FloorToInt(Offset.position), Vector2Int.FloorToInt(playerOffset.position));
            CombatSystem.AddCombatant(this);
        }
        if (path is null || path.Count <= 0)
        {
            CombatSystem.RemoveCombatant(this);
            return;
        }

        var pos = path.Peek().GetVectorInt() - Vector2Int.FloorToInt(Offset.localPosition);
        movement = (pos - (Vector2)transform.position).normalized;
        transform.position += (Vector3)movement * speed.TotalValue * Time.deltaTime;

        if (Vector2.Distance(transform.position, pos) < .1f)
            path.Pop();
    }