Ejemplo n.º 1
0
    public override void Update()
    {
        if (ParentAI.Target == null)
        {
            ParentAI.ClearActions(new AILookForPlayer());
            ParentAI.AddAction(new AIWander());
            End();
            return;
        }

        if (Time.time - lastSync > 2)
        {
            float distance = Helper.DistanceFloatFromTarget(ParentAI.Target.transform.position, ParentAI.transform.position);
            if (distance < ParentAI.Attack.Range)
            {
                ParentAI.AddAction(new AIAttack());
            }

            else if (distance < ParentAI.VisionRange)
            {
                ParentAI.Speed = ParentAI.BaseSpeed * 3.3f;
                ParentAI.Move(ParentAI.Target.transform.position);
            }
            else
            {
                ParentAI.AddAction(new AILookForPlayer());
                ParentAI.AddAction(new AIWander());
                ParentAI.Target = null;
                End();
            }

            lastSync = Time.time;
        }
    }
Ejemplo n.º 2
0
        /// <summary>
        /// The constructor for a player.
        /// </summary>
        public Player(Vector3 Position, ParentAI AI, Animation animation)
            : base(Position)
        {
            this.AI        = AI;
            this.animation = animation;

            UsesIce     = true;
            UsesLadders = true;
        }
Ejemplo n.º 3
0
    public override void Update()
    {
        if (ParentAI.Target == null)
        {
            ParentAI.ClearActions(new AILookForPlayer());
            ParentAI.AddAction(new AIWander());
            End();
            return;
        }
        else
        {
            ParentAI.Stop(ParentAI.Attack.Attack(ParentAI.Target));

            End();
        }
    }
Ejemplo n.º 4
0
 public override void Update()
 {
     if (ParentAI.PatrolPath != null && ParentAI.CurrentPath == null)
     {
         ParentAI.Speed = ParentAI.BaseSpeed;
         Vector3 target = new Vector3(ParentAI.PatrolPath.Points[ParentAI.PatrolPathIndex].x, ParentAI.PatrolPath.Points[ParentAI.PatrolPathIndex].y, 0);
         if (Vector3.Distance(ParentAI.transform.position, target) < ParentAI.PatrolPath.PointRadius)
         {
             ParentAI.PatrolPathIndex++;
         }
         if (ParentAI.PatrolPathIndex >= ParentAI.PatrolPath.Points.Count)
         {
             ParentAI.PatrolPathIndex = 0;
         }
         ParentAI.Move(ParentAI.PatrolPath.Points[ParentAI.PatrolPathIndex]);
     }
     else if (ParentAI.CurrentPath == null)
     {
         ParentAI.Speed = ParentAI.BaseSpeed;
         ParentAI.Move(ParentAI.transform.position + GetRandomDirection());
     }
 }
Ejemplo n.º 5
0
    public override void Update()
    {
        if (Time.time - lastCheck > checkFrequency)
        {
            GameObject playerTarget   = null;
            float      playerDistance = maxDistanceToCheck;

            Vector3 pos = ParentAIGameObject.transform.position;

            GameObject[] players = GameObject.FindGameObjectsWithTag("Player");

            for (int i = 0; i < players.Length; i++)
            {
                float currentPDistance = Helper.DistanceFloatFromTarget(players[i].transform.position, pos);
                if (currentPDistance < playerDistance)
                {
                    RaycastHit2D hit = Physics2D.Raycast(ParentAI.transform.position, players[i].transform.position, currentPDistance, ParentAI.Avoid);

                    Debug.Log("Trying to find player");
                    if (hit.collider == null)
                    {
                        Debug.Log("Player found");
                        playerDistance = currentPDistance;
                        playerTarget   = players[i];
                    }
                }
            }

            if (playerTarget != null)
            {
                ParentAI.ClearActions(new AIChaseTarget());
                ParentAI.Target = playerTarget;
            }

            lastCheck = Time.time;
        }

        base.Update();
    }