Esempio n. 1
0
 void Update()
 {
     if (Input.GetMouseButtonDown(1)) {
         isMove = true;
     }
     if (Input.GetMouseButtonUp(1))
     {
         isMove = false;
     }
     if (!isMove) {
         return;
     }
     MoveTarget();
     GetNeighors();
     if (neighbors != null && neighbors.Count > 0)
     {
         Vector3 v1 = Separation();
         Vector3 v2 = Alignment();
         Vector3 v3 = Cohesion();
         moveDir = (v1 + v2 + v3 + moveDir) / 4;
     }
     transform.forward = moveDir;
     transform.position += moveDir * speed * Time.deltaTime;
     SpacePartition.UpdateAgentCell(this);
 }
Esempio n. 2
0
        private void Awake()
        {
            Transform plane = GameObject.Find("Plane").transform;

            spaceX = plane.localScale.x * 10;
            spaceZ = plane.localScale.z * 10;
            SpacePartition.Init(spaceX, spaceZ, new Vector3(cellSize.x, 10, cellSize.y));
        }
Esempio n. 3
0
        private void OnDrawGizmos()
        {
            List <Cell> cellList = SpacePartition.GetCellList();

            if (cellList == null)
            {
                return;
            }
            for (int i = 0; i < cellList.Count; i++)
            {
                Cell cell = cellList[i];
                if (cell.agentList.Count > 0)
                {
                    Gizmos.color = new Color(0, 1f, 0, 0.2f);
                    Gizmos.DrawCube(cell.bounds.center, cell.bounds.size);
                }
                else
                {
                    Gizmos.color = Color.white;
                    Gizmos.DrawWireCube(cell.bounds.center, cell.bounds.size);
                }
            }
        }