Exemplo n.º 1
0
 private void FixedUpdate()
 {
     if (enableSlam && slamTimer.IsReady(Time.deltaTime))
     {
         ThrowAxe();
         var rayCasts = Physics2D.BoxCastAll(transform.position, new Vector2(4, 4), 0, new Vector2(0, 0));
         SpawnAttackBox(transform.position, new Vector2(4, 4));
         for (var i = 0; i < rayCasts.Length; i++)
         {
             if (rayCasts[i].transform.gameObject.tag == "Player")
             {
                 Debug.Log("Player damaged");
                 //var velocity = (Vector2)(rayCasts[i].transform.position - transform.position).normalized * 10f;
                 //rayCasts[i].rigidbody.velocity += velocity;
                 break;
             }
         }
     }
 }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        RaycastHit2D[] results = Physics2D.BoxCastAll(pos, size, angle, vec, vec.magnitude);
        Debug.DrawRay(pos, vec);
        if (results.Length > 0)
        {
            centroids = new Vector2[results.Length];
        }

        isHit = false;
        for (int i = 0; i < results.Length; ++i)
        {
            RaycastHit2D result = results[i];
            Debug.DrawRay(result.point, result.normal * result.distance);
//			Debug.DrawRay(result.centroid, result.normal * result.distance);
            centroids[i] = result.centroid;
            isHit        = true;
        }
    }
Exemplo n.º 3
0
        public override void MonoUpdate(GameObject gameObject, bool fixedUpdate)
        {
            bool saveProjectiles = projectilesAim || selectTargetOnLaunch || maxPenetratedTargets > 0;

            if (saveProjectiles && fixedUpdate)
            {
                // updates: 10/sec
                if (System.Environment.TickCount % 10 == 0)
                {
                    ProjectileData d = GetData(gameObject);
                    if (d == null || d.proj == null)
                    {
                        return;
                    }

                    if (d.target == null && projectilesAim)
                    {
                        float angle = d.proj.transform.rotation.eulerAngles.z;
                        foreach (RaycastHit2D hit in Physics2D.BoxCastAll(d.proj.transform.position, new Vector2(aimArea, aimArea), angle, d.rb.velocity, aimArea))
                        {
                            if (hit.collider.gameObject.Equals(d.proj))
                            {
                                continue;
                            }

                            Character targetCh = hit.collider.gameObject.GetChar();
                            if (targetCh == null || !Owner.CanAttack(targetCh))
                            {
                                continue;
                            }

                            d.target = targetCh;
                            break;
                        }
                    }

                    if (d.target != null)
                    {
                        AdjustToTarget(d);
                    }
                }
            }
        }
Exemplo n.º 4
0
    public float GetDownForce(List <WeighObject> checkedArr = null)
    {
        float downForce = 0;

        if (checkedArr == null)
        {
            checkedArr = new List <WeighObject>();
        }

        checkedArr.Add(this);

        RaycastHit2D[] hits = Physics2D.BoxCastAll(transform.position, new Vector2(width, height), 0, Vector2.up, 0.1f, checkLayer);


        var check =
            from hit in hits
            //위에있는지
            where (hit.transform.position.Foot(new Vector2(0, height)).y > transform.position.y)
            //이미 확인 했는지
            where (!checkedArr.Exists(a => a.gameObject == hit.transform.gameObject))
            //이 컴포넌트 달려 있는지
            where (hit.transform.GetComponent <WeighObject>())
            //y속도 0인지
            //where (Mathf.Abs(hit.transform.GetComponent<Rigidbody2D>().velocity.y) < 0.1f)
            select hit;

        foreach (RaycastHit2D hit in check)
        {
            if (hit.transform.GetComponent <OBB_Player>() == null && hit.transform.GetComponent <Mob_Base>() == null)
            {
                downForce += hit.transform.GetComponent <WeighObject>().GetDownForce(checkedArr);
            }
            else
            {
                downForce++;
                checkedArr.Add(hit.transform.GetComponent <WeighObject>());
            }
        }

        downForce += mass;

        return(downForce);
    }
Exemplo n.º 5
0
    private bool IsHoveringOverOtherBuilding(Vector3 pos)
    {
        var objects = Physics2D.BoxCastAll(pos, buildingGhost.GetComponent <SpriteRenderer>().sprite.bounds.size * 1.5f, 0, Vector2.zero);

        if (objects.Length == 0)
        {
            return(false);
        }

        foreach (var obj in objects)
        {
            if (obj.transform.GetComponent <Building>() != null)
            {
                return(true);
            }
        }

        return(false);
    }
Exemplo n.º 6
0
 void Interact()
 {
     RaycastHit2D[] hits = Physics2D.BoxCastAll(rb.position + currDirection, new Vector2(0.5f, 0.5f), 0f, Vector2.zero, 0);
     foreach (RaycastHit2D hit in hits)
     {
         if (hit.transform.CompareTag("Chest"))
         {
             hit.transform.GetComponent <Chest>().Interact();
         }
         else if (hit.transform.CompareTag("Storage"))
         {
             hit.transform.GetComponent <Storage>().Interact();
         }
         else if (hit.transform.CompareTag("Shop"))
         {
             hit.transform.GetComponent <Shop>().Interact();
         }
     }
 }
Exemplo n.º 7
0
 public bool CanMoveTo(Vector2 motion, ref RaycastHit2D[] hits)
 {
     if (shapeMode == ShapeMode.Circle)
     {
         hits = Physics2D.CircleCastAll(myTransform.position + (Vector3)offsetFromPivot, radius, motion, motion.magnitude, layerMask);
     }
     else if (shapeMode == ShapeMode.Box)
     {
         hits = Physics2D.BoxCastAll(transform.position + (Vector3)offsetFromPivot, (Vector3)size, 0.0f, motion, motion.magnitude, layerMask);
     }
     foreach (RaycastHit2D hit in hits)
     {
         if (hit.transform.GetInstanceID() != myTransform.GetInstanceID())
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 8
0
 void FixedUpdate()
 {
     RaycastHit2D[] hits = Physics2D.BoxCastAll((Vector2)transform.position + m_BoxCollider2D.offset, m_BoxCollider2D.size, 0, Vector2.up, 0.2f);
     foreach (var h in hits)
     {
         if (h.normal == Vector2.down)
         {
             var bb = h.transform.GetComponent <BeBouncedComponent>();
             if (bb != null && bb.isActiveAndEnabled)
             {
                 if (bb.CanBounced())
                 {
                     m_AudioSource.Play();
                     bb.BeBounced(m_BounceVelocity);
                 }
             }
         }
     }
 }
Exemplo n.º 9
0
    void Spawn()
    {
        Vector3 randomPos = Vector3.zero;
        bool    canSpawn  = false;

        //Physics.BoxCast (레이저를 발사할 위치, 사각형의 각 좌표의 절판 크기, 발사 방향, 충돌 결과, 회전 각도, 최대 거리)
        while (true)
        {
            randomPos = transform.position + new Vector3(Random.Range(-7.5f, 7.5f), Random.Range(-4f, 2.5f), 0);
            RaycastHit2D[] hit = Physics2D.BoxCastAll(randomPos, new Vector2(0.5f, 0.5f), 0, Vector2.down, 0);

            bool can = false;
            foreach (RaycastHit2D c in hit)
            {
                if (c.collider.CompareTag("Wall")) //벽과 닿으면 생성못함
                {
                    first  = randomPos;
                    second = new Vector2(0.5f, 0.5f);
                    can    = true;
                    break;
                }
            }

            if (can == false)
            {
                break;
            }
        }

        int randomMon = Random.Range(0, monsters.Length);

        if (PhotonNetwork.OfflineMode)
        {
            GameObject mon = Instantiate(monsters[randomMon], transform);
            mon.transform.position = randomPos;
        }
        else
        {
            PhotonNetwork.InstantiateRoomObject(monsters[randomMon].name, randomPos, Quaternion.identity);
        }

        Count--;
    }
Exemplo n.º 10
0
        protected override void EveryFrame()
        {
            var rayCasts = Physics2D.BoxCastAll(originRay.position, halfEextens * 2, 0, originRay.forward, maxDistance, layerMask);

            foreach (var ray in rayCasts)
            {
                OnEnter(ray.collider, ray.collider.gameObject);
            }


            for (int i = _activeObjs.Count - 1; i >= 0; i--)
            {
                var active = _activeObjs[i];
                if (!Array.Exists(rayCasts, (RaycastHit2D r) => r.collider == active.Item1))
                {
                    OnExit(active.Item1, active.Item2);
                }
            }
        }
Exemplo n.º 11
0
    public Actor GetNextPetrifiedActorInDirection(FaceDirection direction)
    {
        Vector3Int cellPos        = currentMovePointCellPosition + GridManager.instance.grid.WorldToCell(GridManager.instance.GetFacingDirectionOffsetVector3(direction));
        Vector3    objectPosition = GridManager.instance.cellToworld(cellPos);

        RaycastHit2D[] hit2DArr = Physics2D.BoxCastAll(objectPosition, GridManager.instance.grid.cellSize * GameConfig.boxCastCellSizePercent, 0, objectPosition, 0);
        for (int i = 0; i < hit2DArr.Length; i++)
        {
            Actor actor = hit2DArr[i].collider.GetComponent <Actor>();
            if (actor != null)
            {
                if (actor.isPetrified)
                {
                    return(actor);
                }
            }
        }
        return(this);
    }
Exemplo n.º 12
0
    private void AddBodies(Collider2D collider)
    {
        Rigidbody2D rigidbody = ExtractRigidbody(collider);

        if (rigidbody == null)
        {
            return;
        }

        if (!bodyList.Contains(rigidbody))
        {
            bodyList.Add(rigidbody);
            RaycastHit2D[] raycastHits = Physics2D.BoxCastAll(collider.transform.position, new Vector2(1, 0.4f), 0, Vector2.up, 0.4f);
            foreach (RaycastHit2D hit in raycastHits)
            {
                AddBodies(hit.collider);
            }
        }
    }
Exemplo n.º 13
0
 /// <summary>
 /// Causes this object to melee attack using the desired hit box size, direction, and targeting this objects targetLayer.
 /// </summary>
 /// <param name="direction">Direction to slash in.</param>
 /// <param name="layer">Target layer of objects that can be attacked.</param>
 public void Slash(Vector3 direction)
 {
     if (Time.time > nextSlashTime)
     {
         //app.NotifyAnim(AnimationMessage.SLASH, gameObject);
         RaycastHit2D[] arr = Physics2D.BoxCastAll(gameObject.transform.position, hitBoxSize, 0f, direction, collisionRange, damageableLayer);
         for (int i = 0; i < arr.Length; i++)
         {
             Collider2D coll = arr[i].collider;
             GameObject obj  = coll.gameObject;
             if (knockbackOnHit)
             {
                 KnockBack(obj);
             }
             base.OnOverlap(coll);
         }
         nextSlashTime = Time.time + slashRate;
     }
 }
 void Update()
 {
     if (ColliderEnabled && BoxHitbox.isActiveAndEnabled)
     {
         var cols = Physics2D.BoxCastAll(BoxHitbox.transform.position, BoxHitbox.size, 0, Vector2.zero, 0, DetectionMask);
         if (cols.Length > 0)
         {
             if (!isHit)
             {
                 logger.Log("Collision detected.", this);
                 OnBoxCollisions.Invoke(cols);
                 logger.Log(cols[0].transform.name, this);
                 isHit = true;
             }
             return;
         }
     }
     isHit = false;
 }
Exemplo n.º 15
0
    bool CanSeePlayer()
    {
        Vector2 dir = movement.DirectionToPlayer;

        RaycastHit2D[] hits = Physics2D.BoxCastAll((Vector2)transform.position + dir, new Vector2(1f, 1f), Mathf.Rad2Deg * Mathf.Atan2(dir.y, dir.x), dir, movement.DistanceToPlayer);
        Debug.DrawLine(transform.position, transform.position + (Vector3)(dir * movement.DistanceToPlayer));

        foreach (RaycastHit2D hit in hits)
        {
            if (hit.collider != null)
            {
                if (hit.collider.tag == "Obstacle" || hit.collider.tag == "Enemy")
                {
                    return(false);
                }
            }
        }
        return(true);
    }
Exemplo n.º 16
0
    public CHARACTER_HEALTH[] Melee(Transform transform, Vector2 size)
    {
        float   box_size       = size.x > size.y ? size.y : size.x;
        float   distance       = (size.x > size.y ? size.x : size.y) - box_size;
        float   angle          = transform.eulerAngles.z;
        Vector2 fire_direction = new Vector2(Mathf.Cos(angle * Mathf.Deg2Rad), Mathf.Sin(angle * Mathf.Deg2Rad)).normalized;
        Vector2 start          = new Vector2(transform.position.x, transform.position.y) + (fire_direction * box_size / 2);

        RaycastHit2D[] hits = Physics2D.BoxCastAll(start, Vector2.one * box_size, angle, fire_direction, distance);

        if (debug)
        {
            Vector2 direction = new Vector2(Mathf.Cos((angle + 90f) * Mathf.Deg2Rad), Mathf.Sin((angle + 90f) * Mathf.Deg2Rad));
            Vector2 pointA    = new Vector2(transform.position.x + size.y / 2 * direction.x, transform.position.y + size.y / 2 * direction.y);
            Vector2 pointB    = new Vector2(transform.position.x - size.y / 2 * direction.x, transform.position.y - size.y / 2 * direction.y);
            Vector2 pointC    = new Vector2(pointA.x + size.x * direction.y, pointA.y - size.x * direction.x);
            Vector2 pointD    = new Vector2(pointB.x + size.x * direction.y, pointB.y - size.x * direction.x);
            Debug.DrawLine(pointA, pointB, Color.blue);
            Debug.DrawLine(pointA, pointC, Color.blue);
            Debug.DrawLine(pointB, pointD, Color.blue);
            Debug.DrawLine(pointC, pointD, Color.blue);
        }

        List <CHARACTER_HEALTH> healths = new List <CHARACTER_HEALTH>();

        foreach (RaycastHit2D hit in hits)
        {
            if (hit.transform.GetComponent <CHARACTER_HEALTH>() != null)
            {
                if (hit.transform.GetComponent <CHARACTER_HEALTH>() != self)
                {
                    if (debug)
                    {
                        Debug.DrawRay(hit.point, hit.normal * 0.1f, Color.red);
                    }
                    healths.Add(hit.transform.GetComponent <CHARACTER_HEALTH>());
                }
            }
        }

        return(healths.ToArray());
    }
Exemplo n.º 17
0
    void SetRoomProps(int index)
    {
        Vector2 pos;

        while (true)
        {
            pos = new Vector2(Random.Range((int)map.x, (int)map.y + 1) * 18, Random.Range((int)map.w, (int)map.z + 1) * 10);

            RaycastHit2D[] hit = Physics2D.BoxCastAll(
                pos + objects[index].GetComponent <RoomProps>().offset,
                objects[index].GetComponent <RoomProps>().BoxSize, 0, Vector2.down, 0);

            bool canSpawn = true;
            foreach (RaycastHit2D ray in hit)
            {
                if (ray.collider.CompareTag("Entry") || ray.collider.CompareTag("Aspalt") || ray.collider.CompareTag("Destroyer") || ray.collider.CompareTag("Wall") || ray.collider.CompareTag("SpawnPoint"))
                {
                    canSpawn = false;
                }
            }

            if (canSpawn)
            {
                foreach (RaycastHit2D c in hit)
                {
                    if (c.collider.CompareTag("Space"))
                    {
                        Destroy(c.collider.gameObject);
                    }
                }
                break;
            }
        }
        if (PhotonNetwork.OfflineMode)
        {
            Instantiate(objects[index], pos, quaternion.identity);
        }
        else
        {
            PhotonNetwork.InstantiateRoomObject(objects        [index].name, pos, quaternion.identity);
        }
    }
    protected override void OnUpdate()
    {
        if (this.DataContext.IsTemplate && this.DataContext.type.Equals(ProductType.Building))
        {
            DataContext.XPos = Mathf.Round(GameBoardViewModel.Instance.MousePosition.x);
            DataContext.YPos = Mathf.Round(GameBoardViewModel.Instance.MousePosition.y);

            if (Input.GetMouseButtonDown(0))
            {
                RaycastHit2D[] hits = Physics2D.BoxCastAll((Vector2)transform.position + _collider.offset, _collider.size, transform.eulerAngles.z,
                                                           Vector2.zero, 2f, _tilesLayer);

                if (hits.Length > 0 && CheckTheAreaIsSuitableForBuild(hits))
                {
                    SetGroundTileAsIsNotWalkable(hits);
                    PlaceBuilding();
                }
            }
        }
    }
    public virtual void ApplyBackwardVelocity()
    {
        var pos = transform.position;

        var ray = Physics2D.BoxCastAll(pos, ((BoxCollider2D)Collider2D).size + Vector2.one * (Utils.D2T * 3f),
                                       0, Vector2.up, ((BoxCollider2D)Collider2D).size.y * 0.5f, Utils.FloorMask(gameObject.layer));

        if (ray.Length > 0)
        {
            foreach (var hit in ray)
            {
                var iMov = hit.transform.GetComponent <IMovable>();
                if (iMov != null && iMov != this)
                {
                    print(iMov);
                    iMov.SetVelocity(_velocity * -1.05f, true);
                }
            }
        }
    }
Exemplo n.º 20
0
    public void DoAttack()
    {
        __castDir = _move.GetVectorDirection();

        RaycastHit2D[] hits = Physics2D.BoxCastAll(transform.position, new Vector2(1f, 1f), 0f, __castDir, 2f);

        for (int i = 0; i < hits.Length; i++)
        {
            if (hits[i].transform.CompareTag("Player"))
            {
                hits[i].transform.GetComponent <GayatriCharacter>().ApplyDamage(attackDamage, this.gameObject);
                break;
            }
        }

        if (Task.isInspected)
        {
            Task.current.Succeed();
        }
    }
Exemplo n.º 21
0
    void FixedUpdate()
    {
        float dist = new Vector2(rb.velocity.x, 0).magnitude *Time.fixedDeltaTime;

        RaycastHit2D[] inside      = Physics2D.BoxCastAll(((Vector2)this.transform.position), new Vector2(1, 1), 0, (Vector2)rb.velocity, dist);
        bool           willCollide = false;

        foreach (RaycastHit2D hit in inside)
        {
            willCollide = willCollide || !hit.collider.isTrigger;
            if (willCollide)
            {
                break;
            }
        }
        if (willCollide)
        {
            rb.velocity = new Vector2(0, rb.velocity.y);
        }
    }
Exemplo n.º 22
0
    private IEnumerator Explode()
    {
        ignited = true;
        gameObject.GetComponent <Animator>().SetTrigger("ignite");
        sound.Play();
        yield return(new WaitForSeconds(5f));

        foreach (RaycastHit2D hit in Physics2D.BoxCastAll(this.gameObject.transform.position, new Vector2(explosionSize, explosionSize), 0f, new Vector2(0, 0), 1f))
        {
            if (!hit.collider.gameObject.CompareTag("Player"))
            {
                hit.collider.gameObject.BroadcastMessage("OnDamage", 3);
            }
            else
            {
                hit.collider.gameObject.BroadcastMessage("OnDamage");
            }
        }
        this.gameObject.SetActive(false);
    }
Exemplo n.º 23
0
    /// <summary>
    /// Change raycast because of size
    /// </summary>
    public override void CheckBlockByRaycast()
    {
        Vector2 boxSize = Collider.bounds.size;

        boxSize.x  = .1f;
        boxSize.y *= .5f;
        Vector2 position = new Vector2(IsRight ? Collider.bounds.max.x : Collider.bounds.min.x, Collider.bounds.max.y - boxSize.y / 2);

        position.x += IsRight
            ? boxSize.x / 2
            : -(boxSize.x / 2);

        RaycastHit2D[] hitsBlock = Physics2D.BoxCastAll(position, boxSize, 0f, Vector2.zero, .1f, BlockLayer);
        var            change    = hitsBlock.Length > 0;

        if (change)
        {
            IsRight = !IsRight;
        }
    }
Exemplo n.º 24
0
    public static HitReturn[] BoxHits(Vector2 origin, Vector2 size, float angle, Vector2 direction, float distance, LayerMask hitLayers)
    {
        HitReturn[]    _hitReturns;
        RaycastHit2D[] _hits = Physics2D.BoxCastAll(origin, size, angle, direction, distance, hitLayers); //Grab hits in area
        _hitReturns = new HitReturn[_hits.Length];                                                        //Match array lengths with _hits

        for (int i = 0; i < _hits.Length; i++)                                                            //Loop through hits and add them to HitReturn array
        {
            if (_hits[i].collider != null)
            {
                HitReturn _hitReturn = new HitReturn(_hits[i].collider.gameObject, _hits[i].collider.gameObject.tag, _hits[i]);
                _hitReturns[i] = _hitReturn;
            }
            else
            {
                _hitReturns[i] = null;
            }
        }
        return(_hitReturns);
    }
Exemplo n.º 25
0
    private void Damage()
    {
        for (int i = 0; i < lineRenderers.Length; i++)
        {
            hits = Physics2D.BoxCastAll(transform.position, new Vector2(0.5f * laserWidth, laserLength), angle[i], Vector2.right);
            foreach (RaycastHit2D hit in hits)
            {
                if (hit.transform.gameObject.CompareTag("Player"))
                {
                    if (hit.transform.position.y < transform.position.y - laserWidth / 2)
                    {
                        continue;
                    }
                    hit.transform.gameObject.GetComponent <PlayerStats>().TakeDamage(dps);
                }
            }

            Debug.DrawRay(transform.position, new Vector3(x[i], y[i], 0), Color.red);
        }
    }
Exemplo n.º 26
0
 public bool CanMoveTo(Vector2 motion, ref Vector2 safeMotion, ref RaycastHit2D[] hits)
 {
     if (shapeMode == ShapeMode.Circle)
     {
         hits = Physics2D.CircleCastAll(myTransform.position + new Vector3(offsetFromPivot.x, offsetFromPivot.y, 0.0f), radius, motion, motion.magnitude, layerMask);
     }
     else if (shapeMode == ShapeMode.Box)
     {
         hits = Physics2D.BoxCastAll(transform.position + new Vector3(offsetFromPivot.x, offsetFromPivot.y, 0.0f), new Vector3(size.x, size.y, 0.0f), 0.0f, motion, motion.magnitude, layerMask);
     }
     foreach (RaycastHit2D hit in hits)
     {
         if (hit.transform.GetInstanceID() != myTransform.GetInstanceID())
         {
             safeMotion = ((myTransform.position - (Vector3)hit.point).magnitude - ((shapeMode == ShapeMode.Circle) ? radius : Mathf.Max(size.x, size.y))) * motion.normalized;
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 27
0
    private void Update()
    {
        var pos = transform.position;

        var ray = Physics2D.BoxCastAll(pos, Collider2D.size,
                                       0, Vector2.zero, 0, (1 << 16));

        if (ray.Length > 0)
        {
            foreach (var hit in ray)
            {
                if (hit.collider.gameObject == LittleGirl.self.gameObject)
                {
                    ToNextStage();
                    print("load " + NextStage);
                    Collider2D.enabled = false;
                }
            }
        }
    }
Exemplo n.º 28
0
 public override void Interact()
 {
     RaycastHit2D[] hits = Physics2D.BoxCastAll(coll.transform.position, coll.size, 0f, Vector2.zero, .1f);
     if (BusyCheck())
     {
         return;
     }
     for (int i = 0; i < hits.Length; i++)
     {
         if (hits[i].transform.tag == "Debris")
         {
             if (!hits[i].transform.GetComponent <Debris>().launched)
             {
                 GameController.GetInstance().GainPoint(hits[i].transform.GetComponent <Debris>().pointvalue);
             }
             hits[i].transform.GetComponent <Debris>().Launch();
         }
     }
     SoundPlayer.instance.vent.Play();
 }
Exemplo n.º 29
0
    static public bool CanGo(Vector2 Pos, int Dir, float Speed, Vector2 size, LayerMask wallLayer, bool show = false)
    {
        var sx = Pos - new Vector2(size.x / 2, 0);

        sx.y   += size.y / 2;
        size.y *= 0.99f;
        if (show)
        {
            for (float i = 0.005f; sx.x < (Pos + new Vector2(size.x / 2, 0)).x + (Dir * Speed * Time.fixedDeltaTime); sx.x += i)
            {
                Debug.DrawRay(sx, (Vector2.down * size.y), Color.red);
            }
        }

        var obj = Physics2D.BoxCastAll(Pos, size, 0, Vector2.right * Dir, (Speed * Time.fixedDeltaTime), wallLayer);



        return(!(obj.Length > 0));
    }
Exemplo n.º 30
0
        private void Move()
        {
            // Move position of this NPC.
            transform.position = Vector2.MoveTowards(transform.position, targetPoint, moveSpeed * Time.deltaTime);

            // Change current node or route if the NPC reached at its target node.
            if ((Vector2)transform.position == targetPoint)
            {
                RaycastHit2D[] hits        = Physics2D.BoxCastAll(targetPoint, raycastBox, 0, new Vector2(), 0);
                bool           reachedNode = false;
                foreach (RaycastHit2D hit in hits)
                {
                    if (hit.collider.isTrigger &&
                        hit.collider.gameObject == curRoute.NodeSet[curNodeNum + 1].gameObject)
                    {
                        reachedNode = true;
                    }
                }

                if (reachedNode)
                {
                    int   rand1 = Random.Range(0, mapDataManager.MaxRandomValue);
                    int   rand2 = Random.Range(0, mapDataManager.MaxRandomValue);
                    int   rand3 = Random.Range(0, 2);
                    float randf = Random.Range(1f, 3f);

                    if (PhotonNetwork.connected)
                    {
                        photonView.RPC("ChangeNodeAndRoute", PhotonTargets.All, rand1, rand2, rand3, randf);
                    }
                    else
                    {
                        ChangeNodeAndRoute(rand1, rand2, rand3, randf);
                    }
                }
                else
                {
                    SetNewTargetPoint();
                }
            }
        }