Exemplo n.º 1
0
    public bool hasCreatedHealthPath = false; //to stop the path from being created every time the update ticks
    //works identically to the State_Search_Ammo state
    public override void Execute(Agent agent)
    {
        agent.SB.PursuitOff();
        if (hasCreatedHealthPath == false)
        {
            agent.canMove = true;

            agent.SB.PathOff();
            Astarpathfinding pathFind     = new Astarpathfinding();
            CreateNodes      graphBuilder = new CreateNodes();
            NavGraph         tempGraph    = graphBuilder.createGraph();
            PathFollow       followCode   = new PathFollow();
            FindNearestNode  nodeFinder   = new FindNearestNode();
            pathFind.Initialize(tempGraph);
            pathFind.Check(tempGraph, nodeFinder.FindNearestIndex(agent.transform.position), nodeFinder.FindNearestIndex(agent.closestHp.transform.position));
            followCode.CreatePath(pathFind.Path, tempGraph);
            if (Vector3.Distance(tempGraph.Nodes[followCode.nodePath[0]].position, tempGraph.Nodes[followCode.nodePath[1]].position) > Vector3.Distance(agent.transform.position, tempGraph.Nodes[followCode.nodePath[1]].position) && followCode.nodePath.Count > 1)
            {
                followCode.nodePath.RemoveAt(0);
            }
            agent.SB.path = followCode;
            agent.SB.PathOn();
            hasCreatedHealthPath = true;
        }
        if (Vector3.Distance(agent.transform.position, agent.SB.path.nodeList[agent.SB.path.nodePath[agent.SB.path.nodePath.Count - 1]].position) < 8)
        {
            agent.SB.PathOff();
            agent.SB.SeekOn(agent.closestHp.transform.position, 5);
        }
    }
Exemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        kinematic              = GetComponent <Kinematic>();
        myRotateType           = new LookWhereGoing();
        myRotateType.character = kinematic;

        Graph myGraph = new Graph();

        myGraph.Build();
        List <Connection> path = Dijkstra.pathfind(myGraph, start, goal);

        // path is a list of connections - convert this to gameobjects for the FollowPath steering behavior
        myPath = new Kinematic[path.Count + 1];
        int i = 0;

        foreach (Connection c in path)
        {
            Debug.Log("from " + c.getFromNode() + " to " + c.getToNode() + " @" + c.getCost());
            myPath[i] = c.getFromNode().GetComponent <Kinematic>();
            i++;
        }
        myPath[i] = goal.GetComponent <Kinematic>();

        myMoveType           = new PathFollow();
        myMoveType.character = kinematic;
        myMoveType.path      = myPath;
    }
Exemplo n.º 3
0
        public void Execute()
        {
            DynamicBuffer <PathPosition> pathPositionBuffer = pathPositionBufferFromEntity[entity];

            pathPositionBuffer.Clear();

            PathfindingParams pathfindingParams = pathfindingParamsComponentDataFromEntity[entity];
            int endNodeIndex = CalculateIndex(pathfindingParams.endPosition.x, pathfindingParams.endPosition.y, gridSize.x);

            // Выход за пределы карты
            if (endNodeIndex >= gridSize.x * gridSize.y && endNodeIndex >= 0)
            {
                pathFollowComponentDataFromEntity[entity] = new PathFollow {
                    pathIndex = -1
                };
                return;
            }
            PathNode endNode = pathNodeArray[endNodeIndex];

            if (endNode.cameFromNodeIndex == -1)
            {
                // Didn't find a path!
                pathFollowComponentDataFromEntity[entity] = new PathFollow {
                    pathIndex = -1
                };
            }
            else
            {
                // Found a path
                CalculatePath(pathNodeArray, endNode, pathPositionBuffer);
                pathFollowComponentDataFromEntity[entity] = new PathFollow {
                    pathIndex = pathPositionBuffer.Length - 1
                };
            }
        }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        if (target != null)
        {
            aimTowards(target.transform.position);
        }

        staticAnimation();

        Collider[] inRange = Physics.OverlapSphere(transform.position, range);

        int maxPath = 0;

        //target = null;
        foreach (Collider c in inRange)
        {
            PathFollow mob = c.gameObject.GetComponent <PathFollow>();
            if (mob != null && mob.nextNode.pathId > maxPath)
            {
                target  = c.transform;
                maxPath = mob.nextNode.pathId;
            }
        }

        fireTimer += Time.deltaTime;
        if (fireTimer >= fireDelay && target != null)
        {
            aimTowards(target.transform.position);
            fire();
        }
    }
Exemplo n.º 5
0
        /// <summary>
        /// Returns true if tha agent is driving
        /// </summary>
        private bool IsCarDriving(PathFollow car)
        {
            float carOffset = car.UnitOffset;

            if (carOffset < PathCheckpoint)
            {
                IsCarAtCheckpoint = false;
                IsCarUnderBarrier = false;
                return(true);
            }
            if (carOffset < PathCheckpointCollisionStart)
            {
                IsCarAtCheckpoint = true;
                IsCarUnderBarrier = false;
                return(GetNode <ElectricalBarrierNode>(_barrierPath).IsVisiblyOpen);
            }
            if (carOffset < PathCheckpointPassed)
            {
                IsCarAtCheckpoint = false;
                IsCarUnderBarrier = true;
                return(GetNode <ElectricalBarrierNode>(_barrierPath).IsVisiblyOpen);
            }
            IsCarAtCheckpoint = false;
            IsCarUnderBarrier = false;
            return(true);
        }
Exemplo n.º 6
0
    private void Start()
    {
        switch (choiceOfBehavior)
        {
        case SteeringBehaviors.PathFinder:

            myRotateType           = new LookWhereGoing();
            myRotateType.character = this;
            myRotateType.target    = newTarget;
            myGraph.Build();
            List <Connection> path = Dijkstra.pathfind(myGraph, start, goal);
            // path is a list of connections - convert this to gameobjects for the FollowPath steering behavior
            myPath = new GameObject[path.Count + 1];
            int k = 0;
            foreach (Connection c in path)
            {
                Debug.Log("from " + c.getFromNode() + " to " + c.getToNode() + " @" + c.getCost());
                myPath[k] = c.getFromNode().gameObject;
                k++;
            }
            myPath[k]            = goal.gameObject;
            myMoveType           = new PathFollow();
            myMoveType.character = this;
            myMoveType.path      = myPath;
            break;
        }
    }
Exemplo n.º 7
0
        public void Execute()
        {
            DynamicBuffer <PathPosition> pathPositionBuffer = pathPositionBufferFromEntity[entity];

            pathPositionBuffer.Clear();
            DestinationComponent destination = destinationComponentDataFromEntity[entity];
            int      endNodeIndex            = CalculateIndex(destination.endPosition.x, destination.endPosition.y, gridSize.x);
            PathNode endNode = pathNodeArray[endNodeIndex];

            if (endNode.cameFromNodeIndex == -1)
            {
                //Debug.Log("Didn't find a path!");
                pathFollowComponentDataFromEntity[entity] = new PathFollow {
                    pathIndex = -1
                };
            }
            else
            {
                // Found a path
                CalculatePath(pathNodeArray, endNode, pathPositionBuffer);
                pathFollowComponentDataFromEntity[entity] = new PathFollow {
                    pathIndex = pathPositionBuffer.Length - 1
                };
            }
        }
    // Use this for initialization
    void Start()
    {
        bt_next.SetActive(false);
        bt_insertAlcool.SetActive(false);
        bt_moveToEspec.SetActive(false);
        bt_calculoAlcool.SetActive(false);
        bt_removeCubeta.SetActive(false);
        bt_addSolution.SetActive(false);
        bt_calculoEspec.SetActive(false);
        bt_restart.SetActive(false);

        listDialog.Add(Resources.Load <Sprite> ("espec_text_1"));
        listDialog.Add(Resources.Load <Sprite> ("espec_text_2"));
        listDialog.Add(Resources.Load <Sprite> ("espec_text_3"));
        listDialog.Add(Resources.Load <Sprite> ("espec_text_4"));
        listDialog.Add(Resources.Load <Sprite> ("espec_text_5"));
        listDialog.Add(Resources.Load <Sprite> ("espec_text_6"));
        listDialog.Add(Resources.Load <Sprite> ("espec_text_7"));
        listDialog.Add(Resources.Load <Sprite> ("espec_text_8"));
        listDialog.Add(Resources.Load <Sprite> ("espectrofotometro_text"));
        listDialog.Add(Resources.Load <Sprite> ("espec_text_9"));

        wait = GameObject.Find("espectrofotometro").GetComponent <WaitClass> ();

        absText.text = "Abs: " + absorvancia;
        traText.text = "TR: " + transmitancia;
        conText.text = "C: " + concentracao;
        eText.text   = "E: " + coeficienteAbs;

        currentState           = EspecStates.step0;
        textDialogEspec.sprite = listDialog [0];

        pathFollow = GameObject.Find("Camera").GetComponent <PathFollow> ();
    }
Exemplo n.º 9
0
    private void FollowPath(List <CubeIndex> path)
    {
        PathFollow pathFollow = GetComponent <PathFollow>();

        pathFollow.pathNodes = path;
        pathFollow.enabled   = true;
    }
Exemplo n.º 10
0
    // Start is called before the first frame update
    void Start()
    {
        myRotateType        = new LookWhereGoing();
        myRotateType.ai     = this;
        myRotateType.target = target;

        Graph myGraph = new Graph();

        myGraph.Build();
        List <Connection> path = Dijkstra.pathfind(myGraph, start, goal, useTactical);

        // path is a list of connections - convert this to gameobjects for the FollowPath steering behavior
        myPath = new GameObject[path.Count + 1];
        int i = 0;

        foreach (Connection c in path)
        {
            Debug.Log("from " + c.getFromNode() + " to " + c.getToNode() + " @" + c.getCost(useTactical));
            myPath[i] = c.getFromNode().gameObject;
            i++;
        }
        myPath[i] = goal.gameObject;

        myMoveType                 = new PathFollow();
        myMoveType.ai              = this;
        myMoveType.path            = myPath;
        myMoveType.maxAcceleration = maxAcceleration;
        myMoveType.maxSpeed        = maxSpeed;
    }
        private static void CalculatePath(NativeHashMap <int, PathNode> pathNodeMap, PathNode endNode, DynamicBuffer <PathCell> pathPointBuffer, ref PathFollow pathFollow)
        {
            //Didnt find a path!
            if (endNode.PreviousNodeIndex == -1)
            {
                pathFollow = new PathFollow {
                    PathIndex = -1
                };
                return;
            }
            else
            {
                pathPointBuffer.Add(new PathCell {
                    Cell = new int2(endNode.X, endNode.Y)
                });

                PathNode currentNode = endNode;

                while (currentNode.PreviousNodeIndex != -1)
                {
                    PathNode previousNode = pathNodeMap[currentNode.PreviousNodeIndex];
                    pathPointBuffer.Add(new PathCell {
                        Cell = new int2(previousNode.X, previousNode.Y)
                    });
                    currentNode = previousNode;
                }

                pathFollow = new PathFollow {
                    PathIndex = pathPointBuffer.Length - 1
                };
            }
        }
Exemplo n.º 12
0
 public static PathFollow GetInstance()
 {
     if (instance == null)
     {
         instance = new PathFollow();
     }
     return(instance);
 }
Exemplo n.º 13
0
    private void Start()
    {
        kinematic = GetComponent <Kinematic>();

        switch (moveType)
        {
        case SteeringType.Pursue:
            pursueAI           = new Pursue();
            pursueAI.character = kinematic;
            pursueAI.target    = target;
            break;

        case SteeringType.Evade:
            evadeAI           = new Evade();
            evadeAI.character = kinematic;
            evadeAI.target    = target;
            break;

        case SteeringType.FollowPath:
            followAI           = new PathFollow();
            followAI.character = kinematic;
            followAI.path      = pathOfObjects;
            break;

        case SteeringType.Seek:
            seekAI           = new Seek();
            seekAI.character = kinematic;
            seekAI.target    = target;
            break;

        case SteeringType.Flee:
            fleeAI           = new Flee();
            fleeAI.character = kinematic;
            fleeAI.target    = target;
            break;

        case SteeringType.Seperation:
            seperationAI           = new Seperation();
            seperationAI.character = kinematic;
            seperationAI.targets   = seperateObstacles;
            break;

        case SteeringType.Arrive:
            arriveAI           = new Arrive();
            arriveAI.character = kinematic;
            arriveAI.target    = target;
            break;
        }

        switch (lookType)
        {
        case LookType.Align:
            alignAI           = new Align();
            alignAI.character = kinematic;
            alignAI.target    = target;
            break;
        }
    }
Exemplo n.º 14
0
    public void OnTriggerEnter(Collider collision)
    {
        PathFollow mob = collision.gameObject.GetComponent <PathFollow>();

        if (mob != null)
        {
            target = mob.transform;
        }
        //Debug.Log(collision.ToString());
    }
    void Start()
    {
        animator       = GameObject.Find("Camera").GetComponent <MenuAnimator> ();
        itemController = GameObject.Find("Canvas").GetComponent <ItemController>();
        pathFollow     = GameObject.Find("Camera").GetComponent <PathFollow> ();
        prepareObject  = GameObject.Find("GameController").GetComponent <Preparation> ();
        especObject    = GameObject.Find("espectrofotometro").GetComponent <Espectrofotometro> ();

        currentState = GameState.none;
    }
Exemplo n.º 16
0
    // Start is called before the first frame update
    void Start()
    {
        myMoveType           = new PathFollow();
        myMoveType.character = this;
        myMoveType.path      = path;
        myMoveType.target    = path[0];

        myRotateType           = new LookWhereGoing();
        myRotateType.character = this;
    }
Exemplo n.º 17
0
    }                                   //Aciona o menu somente quando a câmera chegar no seu devido lugar

    void Start()
    {
        //chamadas iniciais scripts
        itemController = GameObject.Find("Canvas").GetComponent <ItemController>();
        animStart      = GameObject.Find("Iniciar").GetComponent <Animator>();
        pathFollow     = GetComponent <PathFollow> ();
        initialFollow  = GetComponent <LabInitialFollow> ();
        espec          = GameObject.Find("espectrofotometro").GetComponent <Espectrofotometro> ();
        cubetaPath     = GameObject.Find("Cubeta").GetComponent <CubetaMove> ();
    }
    // Start is called before the first frame update
    void Start()
    {
        myRotateType           = new LookWhereGoing();
        myRotateType.character = this;
        myRotateType.target    = myTarget;

        myMoveType           = new PathFollow();
        myMoveType.character = this;
        //myMoveType.target = myTarget;
        myMoveType.path = myPath;
    }
Exemplo n.º 19
0
    private void OnPathReceived(Path path)
    {
        if (!behaviours.Contains(PathFollow.GetInstance()))
        {
            behaviours.Add(PathFollow.GetInstance());
        }

        requestSend = false;
        this.path   = path;
        this.path.Simplify();
        this.path.SmoothQuick();
    }
Exemplo n.º 20
0
    // Start is called before the first frame update
    void Start()
    {
        nodes = GameObject.FindGameObjectsWithTag("Node");

        myRotateType           = new LookWhereGoing();
        myRotateType.character = this;
        myRotateType.target    = myTarget;

        myMoveType           = new PathFollow();
        myMoveType.character = this;
        getPath();
    }
Exemplo n.º 21
0
    // Update is called once per frame
    void Update()
    {
        if (pulsing)
        {
            pulseTime += Time.deltaTime;
            if (pulseTime >= pulseLength)
            {
                pulseTime = 0;
                pulsing   = false;
                pulse.transform.localScale = Vector3.zero;
                pulseMat.SetFloat("_Strength", 9);
            }
            else
            {
                float amount       = pulseTime / pulseLength;
                float amountScaled = amount * .7854f + .7854f;
                pulse.transform.localScale = Vector3.one * 1.5f + Vector3.one * ((Mathf.Sin(amountScaled) - .7071f) * range) / 0.29289f;
                pulseMat.SetFloat("_Strength", 10f - amount * 9);
                pulseLight.intensity = 5 - amount * 5;
                //float amount = (pulseTime / pulseLength) * 10 + .25f;
                //pulse.transform.localScale = Vector3.one * ((Mathf.Log(amount) + 1.39f) / 3.7f * range);
            }
        }
        else
        {
            fireTimer += Time.deltaTime;
            pulse.transform.localScale = Vector3.one * 1.5f * (fireTimer / fireDelay);
            if (fireTimer >= fireDelay)
            {
                fireTimer = 0;
                Collider[] colliders = Physics.OverlapSphere(transform.position, range);
                bool       inRange   = false;

                foreach (Collider c in colliders)
                {
                    PathFollow mob = c.gameObject.GetComponent <PathFollow>();
                    if (mob != null)
                    {
                        inRange = true;
                        if (mob.takeDamage(damage) && upgradeLevel == 3 && Random.value <= secondaryChance)
                        {
                            Instantiate(mobPulse.gameObject, c.transform.position, Quaternion.identity);
                        }
                    }
                }
                if (inRange)
                {
                    fire();
                }
            }
        }
    }
Exemplo n.º 22
0
        private void CheckCollision(ElectricalBarrier master)
        {
            PathFollow car        = GetNode <PathFollow>("VehiclePath/PathFollow");
            float      unitOffset = car.UnitOffset;

            if (unitOffset > PathCheckpointCollisionStart && unitOffset < PathCheckpointCollisionEnd)
            {
                if (master.Barrier.BarrierRotation < 10)
                {
                    BreakDown();
                }
            }
        }
Exemplo n.º 23
0
    void OnTriggerEnter(Collider collision)
    {
        PathFollow mob = collision.gameObject.GetComponent <PathFollow>();

        if (mob != null)
        {
            mob.takeDamage(damage);
            if (drain != 0)
            {
                mob.applyEffect(drain, drainLength);
            }
            GameObject.Destroy(gameObject);
        }
    }
Exemplo n.º 24
0
    public bool hasCreatedPath = false; //to stop the path from being created every time the update ticks

    //on execute the state will create a new A* graph that will find the shortest route to the position of the "closestAmmo" object in the world.
    public override void Execute(Agent agent)
    {
        agent.SB.PursuitOff();
        if (hasCreatedPath == false)
        {
            agent.canMove = true;
            agent.SB.PathOff();
            Astarpathfinding pathFind     = new Astarpathfinding();
            CreateNodes      graphBuilder = new CreateNodes();
            NavGraph         tempGraph    = graphBuilder.createGraph();
            PathFollow       followCode   = new PathFollow();
            FindNearestNode  nodeFinder   = new FindNearestNode();
            pathFind.Initialize(tempGraph);
            pathFind.Check(tempGraph, nodeFinder.FindNearestIndex(agent.transform.position), nodeFinder.FindNearestIndex(agent.closestAmmo.transform.position));
            followCode.CreatePath(pathFind.Path, tempGraph);
            if (followCode.nodePath.Count > 1)
            {
                if (Vector3.Distance(tempGraph.Nodes[followCode.nodePath[0]].position, tempGraph.Nodes[followCode.nodePath[1]].position) > Vector3.Distance(agent.transform.position, tempGraph.Nodes[followCode.nodePath[1]].position))
                {
                    //if the AI is closer to the second node in the path than the first node is it means that the AI has passed the first node, and as such it is no longer needed and can be removed.
                    followCode.nodePath.RemoveAt(0);
                    Debug.Log("new first node is " + followCode.nodePath[0]);
                }
            }

            agent.SB.path = followCode;
            agent.SB.PathOn();
            hasCreatedPath = true;
            Debug.Log("searching for ammo");
        }
        //while there are still nodes in the path to the ammo
        if (agent.SB.path.nodePath.Count > 1)
        {
            //if it is within 8 units of the last node in the path the agent will begin to seek towards the actual ammo position instead
            if (Vector3.Distance(agent.transform.position, agent.SB.path.nodeList[agent.SB.path.nodePath[agent.SB.path.nodePath.Count - 1]].position) < 8)
            {
                agent.SB.PathOff();
                agent.SB.SeekOn(agent.closestAmmo.transform.position, 2);
            }
        }
        else
        {
            //if the AI is already next to the ammo when the state is executed it will simply seek to the ammo immediately
            agent.SB.PathOff();
            agent.SB.SeekOn(agent.closestAmmo.transform.position, 2);
        }


        //agent.patrolCounter++;
    }
Exemplo n.º 25
0
        /// <summary>
        /// Calculates the next simulation step.
        /// </summary>
        public void Update(ElectricalBarrier master, int deltaTime)
        {
            PathFollow car = GetNode <PathFollow>("VehiclePath/PathFollow");

            if (IsCarDriving(car))
            {
                OnDriving(car, master, deltaTime);
            }
            else
            {
                OnWait(master, deltaTime);
            }
            CheckCollision(master);
        }
Exemplo n.º 26
0
    void OnTriggerExit(Collider other)
    {
        for (int i = 0; i < _tag.Length; i++)
        {
            if (other.transform.parent.tag == _tag[i])
            {
                PathFollow otherPathFollow = other.transform.GetComponentInParent <PathFollow>();
                _isActive[i] = false;

                if (otherPathFollow)
                {
                    otherPathFollow.CarBehindThisCarIsFollowingTheSamePath = false;
                }
            }
        }
    }
Exemplo n.º 27
0
        //Display Object Image Corona Object
        public CoronaObject(Point location, Image image)
        {
            Events           = new List <CoronaEvent>();
            Timers           = new List <CoronaTimer>();
            this.PhysicsBody = new PhysicsBody(this);
            this.PathFollow  = new PathFollow(this);

            DisplayObject   = new DisplayObject(image, location, this);
            this.isSelected = false;
            isVisible       = true;

            onStartFunction  = "function() \n\n end";
            onPauseFunction  = " function() \n\n end";
            onDeleteFunction = "function() \n\n end";

            this.IsHandledByTilesMap = false;
        }
Exemplo n.º 28
0
    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        if (timer >= duration)
        {
            GameObject.Destroy(gameObject);
        }

        Collider[] hit = Physics.OverlapSphere(transform.position, range);
        foreach (Collider c in hit)
        {
            PathFollow mob = c.gameObject.GetComponent <PathFollow>();
            if (mob != null)
            {
                mob.takeDamage(damage * Time.deltaTime);
            }
        }
    }
Exemplo n.º 29
0
    // Start is called before the first frame update
    void Start()
    {
        myMoveType           = new PathFollow();
        myMoveType.character = this;
        myMoveType.path      = path;
        myMoveType.target    = path[0];
        for (int i = 1; i < path.Length; i++)
        {
            if ((this.transform.position - path[i].transform.position).magnitude < (this.transform.position - myMoveType.target.transform.position).magnitude)
            {
                myMoveType.target           = path[i];
                myMoveType.currentPathIndex = i;
            }
        }

        myRotateType           = new Face();
        myRotateType.character = this;
        myRotateType.target    = myTarget;
    }
Exemplo n.º 30
0
    // Update is called once per frame
    void Update()
    {
        if (!pulsing)
        {
            delayTime += Time.deltaTime;
            if (delayTime > delay)
            {
                pulsing = true;
                audio.Play();

                Collider[] colliders = Physics.OverlapSphere(transform.position, range);
                foreach (Collider c in colliders)
                {
                    PathFollow mob = c.gameObject.GetComponent <PathFollow>();
                    if (mob != null)
                    {
                        if (mob.takeDamage(damage) && depth <= maxDepth && Random.value <= secondaryChance)
                        {
                            GameObject newPulse = Instantiate(gameObject, c.transform.position, Quaternion.identity) as GameObject;
                            MobPulse   pulse    = newPulse.GetComponent <MobPulse>();
                            pulse.damage = damage * .5f;
                            pulse.range  = range * .5f;
                            pulse.depth  = depth + 1;
                        }
                    }
                }
            }
        }
        if (pulsing)
        {
            pulseTime += Time.deltaTime;

            if (pulseTime >= pulseLength)
            {
                GameObject.Destroy(gameObject);
            }

            float amount       = pulseTime / pulseLength;
            float amountScaled = amount * .7854f + .7854f;
            transform.localScale = Vector3.one * 1.5f + Vector3.one * ((Mathf.Sin(amountScaled) - .7071f) * range) / 0.29289f;
            renderer.material.SetFloat("_Strength", 10f - amount * 9);
        }
    }