Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        // if no movement and no target
        // => not moving/reached destination
        if (!startMoving && FinalTarget == Vector3.one * 99999)
        {
            // check if the target has moved location
            // => follow him
            if (Vector3.Distance(followTargetObj.transform.position, _finalFollowTarget) > 0.001f)
            {
                _finalFollowTarget = followTargetObj.transform.position;
                FinalTarget        = followTargetObj.transform.position;
            }
        }
        // if no movement and there is a target and did not reach location of target
        // => get path using A* and start moving
        if (!startMoving && FinalTarget != Vector3.one * 99999 && transform.position != FinalTarget)
        {
            roadToTake = AStarFunctions.AStar(_position, FinalTarget - MapCreate.PositionStarter);

            ScoreFar.text = "x" + roadToTake.Count;

            // reset few variables
            FinalTarget = Vector3.one * 99999;
            startMoving = true;

            nextDirection();
            t = 0;
            anim.SetBool("walk", true);
        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        // not moving and there is a target and we did not reach it
        // => get A* path and start moving
        if (!startMoving && FinalTarget != Vector3.one * 99999 && transform.position != FinalTarget)
        {
            roadToTake = AStarFunctions.AStar(_position, FinalTarget - MapCreate.PositionStarter);

            FinalTarget = Vector3.one * 99999;
            startMoving = true;
            nextDirection();
            t = 0;
            anim.SetBool("walk", true);
        }
    }
    public void HighlightPath(Vector3 block_position)
    {
        if (!_inputFrozen)
        {
            if (_moveController._movementType == MovementType.Grid)
            {
                _path = AStarFunctions.AStar(
                    MapCreate.PositionReference,
                    _controlledCharacter.transform.position,
                    block_position,
                    _controlledCharacter.AffinityColor,
                    _controlledCharacter.MaxSquares - _controlledCharacter.PlayedSquares,
                    _partyController.GetCharactersQueue());
            }
            else if (_moveController._movementType == MovementType.Free)
            {
                _path = new Stack();
                bool occupied = false;
                foreach (CharacterComponent comp in _partyController.GetCharactersQueue())
                {
                    Vector3 vect_comp = comp.transform.position;
                    if (Vector3.Distance(vect_comp, block_position) < 0.1f)
                    {
                        occupied = true;
                        break;
                    }
                }
                if (!occupied)
                {
                    Vector3 vec_block_pos = block_position - MapCreate.PositionReference;
                    _path.Push(new Vector2(-vec_block_pos.z, vec_block_pos.x));
                }
            }

            foreach (Vector2 arrayPos in _path)
            {
                Map.MapGameObjects [(int)arrayPos.x, (int)arrayPos.y].transform.GetChild(0).GetComponent <BlockPropertyChanger> ().HighlightMaterial();
            }
        }
    }