Esempio n. 1
0
    public override object Process(TankManager manager, object state = null)
    {
        AITankControllerState aiState = (AITankControllerState)state;

        if (aiState != null)
        {
            TankManager lastTarget = aiState.target;
            aiState.target = FindTarget(manager);

            if (aiState.target != null)
            {
                manager.GetComponent <Pathfinding.Seeker>().StartPath(manager.transform.position, aiState.target.transform.position, (Path p) => { aiState.currentPath = p; aiState.currentWaypoint = 0; Debug.Log("Ai found Path"); });
            }
            Debug.Log("Ai update");

            if (aiState.currentPath != null)
            {
                if (aiState.currentWaypoint >= aiState.currentPath.vectorPath.Count)
                {
                    manager.tankMovement.targetSpeed = 0;
                    return(aiState);
                }
                else
                {
                    Vector2 waypoint = aiState.currentPath.vectorPath[aiState.currentWaypoint];
                    if (Vector2.Distance(manager.transform.position, waypoint) <= 5)
                    {
                        aiState.currentWaypoint++;
                        return(aiState);
                    }

                    Vector2 direction = (waypoint - (Vector2)manager.transform.position).normalized;

                    manager.tankMovement.targetSpeed  = 1;
                    manager.tankMovement.targetVector = direction;
                }
            }

            return(aiState);
        }
        return(state);
    }
Esempio n. 2
0
 public override void Process()
 {
     state = (AITankControllerState)controller.Process(this, state);
 }