Exemplo n.º 1
0
        public void RunFrom(AiComponentController controller, Transform from)
        {
            Transform transform = controller.transform;
            // store the starting transform
            Transform startTransform = transform;

            //temporarily point the object to look away from the player
            transform.rotation = Quaternion.LookRotation(transform.position - from.position);

            //Then we'll get the position on that rotation that's multiplyBy down the path (you could set a Random.range
            // for this if you want variable results) and store it in a new Vector3 called runTo
            Vector3 runTo = transform.position + transform.forward * 20;
            //Debug.Log("runTo = " + runTo);

            //So now we've got a Vector3 to run to and we can transfer that to a location on the NavMesh with samplePosition.

            NavMeshHit hit; // stores the output in a variable called hit

            // 5 is the distance to check, assumes you use default for the NavMesh Layer name
            NavMesh.SamplePosition(runTo, out hit, 5, 1 << NavMesh.GetNavMeshLayerFromName("Default"));
            //Debug.Log("hit = " + hit + " hit.position = " + hit.position);

            // just used for testing - safe to ignore

            // reset the transform back to our start transform
            transform.position = startTransform.position;
            transform.rotation = startTransform.rotation;

            // And get it to head towards the found NavMesh position
            controller.navMeshAgent.SetDestination(hit.position);
        }
Exemplo n.º 2
0
 private void DoActions(AiComponentController controller)
 {
     for (int i = 0; i < actions.Length; i++)
     {
         actions [i].Act(controller);
     }
 }
Exemplo n.º 3
0
 public override void Act(AiComponentController controller)
 {
     if (controller.isChaseing)
     {
     }
     //controller;
 }
Exemplo n.º 4
0
        public override bool Decide(AiComponentController controller)
        {
            if (PlayerController.playerTransform != null && controller.brain != null && controller.chaser == null)
            {
                List <AiComponent> agents = controller.getAgentsInRange(controller.brain.getSensorRange());
                if (agents.Count > 1)
                {
                    foreach (AiComponent agent in agents)
                    {
                        if (controller.tag == "DOG" && agent.getController().tag == "CAT")
                        {
                            return(false);
                        }
                    }
                }
                //   if(Vector3.Distance(controller.transform.position,agent.getController().transform.position)<=controller.brain.getSensorRange())
                // return false;

                if (Vector3.Distance(controller.transform.position, PlayerController.playerTransform.position) <= controller.brain.getSensorRange())
                {
                    controller.chasing = PlayerController.playerTransform;
                    return(true);
                }
                return(false);
            }
            return(false);
        }
Exemplo n.º 5
0
 public override bool Decide(AiComponentController controller)
 {
     if (controller.tag == "CAT" && controller.chaser != null)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 6
0
        public override void Act(AiComponentController controller)
        {
            // if(checkAttackDistance( controller.chasing, controller.chaser)){
            //TODO: start attack animation
            //TODO: call the damage script onthe target
            //}

            RunFrom(controller, controller.chaser);
        }
Exemplo n.º 7
0
 public override void Act(AiComponentController controller)
 {
     // if(checkAttackDistance( controller.chasing, controller.chaser)){
     //TODO: start attack animation
     //TODO: call the damage script onthe target
     //}
     if (controller.chasing != null)
     {
         controller.navMeshAgent.SetDestination(controller.chasing.position);
     }
 }
Exemplo n.º 8
0
        public override void Act(AiComponentController controller)
        {
            if (temp == null)
            {
                temp = new Vector3();
            }
            if (temp == point)
            {
                point = controller.getRandomMovementPoint();
            }

            controller.navMeshAgent.SetDestination(point);
            temp = point;
        }
Exemplo n.º 9
0
 private void CheckTransitions(AiComponentController controller)
 {
     for (int i = 0; i < transitions.Length; i++)
     {
         bool decisionSucceeded = transitions[i].decision.Decide(controller);
         if (decisionSucceeded)
         {
             controller.TransitionToState(transitions[i].trueState);
         }
         else
         {
             controller.TransitionToState(transitions[i].falseState);
         }
     }
 }
Exemplo n.º 10
0
        public override bool Decide(AiComponentController controller)
        {
            List <AiComponent> agents = controller.getAgentsInRange(controller.brain.getSensorRange());

            if (agents.Count > 1)
            {
                foreach (AiComponent agent in agents)
                {
                    if (controller.tag == "DOG" && agent.getController().tag == "CAT")
                    {
                        //TODO: find cat in range

                        controller.chasing = getNearest(controller, agents).getController().transform;
                        agent.getController().chaser = controller.transform;
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 11
0
        public override bool Decide(AiComponentController controller)
        {
            System.Collections.Generic.List <AiComponent> agents = controller.getAgentsInRange(controller.brain.getSensorRange());
            if (agents.Count > 1)
            {
                foreach (AiComponent agent in agents)
                {
                    if (agent.getController().tag == "CAT")
                    {
                        return(false);
                    }
                }
            }

            if (Vector3.Distance(controller.transform.position, PlayerController.playerTransform.position) <= controller.brain.getSensorRange())
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 12
0
        private AiComponent getNearest(AiComponentController controller, List <AiComponent> agents)
        {
            AiComponent near = null;

            foreach (AiComponent agent in agents)
            {
                if (agent.getController().tag == "CAT")
                {
                    if (near == null)
                    {
                        near = agent;
                    }
                    else
                    {
                        if (Vector3.Distance(controller.transform.position, agent.getController().transform.position)
                            <= Vector3.Distance(controller.transform.position, near.getController().transform.position))
                        {
                            near = agent;
                        }
                    }
                }
            }
            return(near);
        }
Exemplo n.º 13
0
 public abstract bool Decide(AiComponentController controller);
Exemplo n.º 14
0
 public void UpdateState(AiComponentController controller)
 {
     DoActions(controller);
     CheckTransitions(controller);
 }
Exemplo n.º 15
0
 public override bool Decide(AiComponentController controller)
 {
     return(false);
 }
Exemplo n.º 16
0
 public override void Act(AiComponentController controller)
 {
 }
Exemplo n.º 17
0
 public abstract void Act(AiComponentController controller);