// Update is called once per frame void Update() { if (transform.position != TargetPosition) { transform.position = Vector3.Lerp(transform.position, TargetPosition, Time.deltaTime * 50.0f); } else { if (CurrentNode < smoothPath.Count - 1) { ++CurrentNode; TargetPosition = ExportNavMeshToObj.ToUnityVector(smoothPath[CurrentNode]); } } if (crowd != null) { //Agent[] agents = new Agent[crowd.GetAgentCount()]; for (int i = 0; i < crowd.GetAgentCount(); ++i) { lastPosition[i] = crowd.GetAgent(i).Position; //agents[i] = crowd.GetAgent(i); } //crowd.UpdateTopologyOptimization(agents, crowd.GetAgentCount(), Time.deltaTime); crowd.Update(Time.deltaTime); for (int i = 0; i < crowd.GetAgentCount(); ++i) { try { //Debug.DrawLine(ExportNavMeshToObj.ToUnityVector(lastPosition[i]), ExportNavMeshToObj.ToUnityVector(crowd.GetAgent(i).Position), Color.green, 1); mob[i].transform.position = ExportNavMeshToObj.ToUnityVector(crowd.GetAgent(i).Position); } catch { } } } if (Application.platform == RuntimePlatform.WindowsEditor) { // 현재 플랫폼이 Window 에디터인지 if (Input.GetMouseButtonDown(0)) { Vector3 p = Input.mousePosition; Ray cast = Camera.main.ScreenPointToRay(Input.mousePosition); // Mouse의 포지션을 Ray cast 로 변환 UnityEngine.RaycastHit hit; if (Physics.Raycast(cast, out hit)) { Debug.Log($"hit x {hit.point.x}, y {hit.point.y}, z {hit.point.z}"); var newPt = navMeshQuery.FindNearestPoly(ExportNavMeshToObj.ToSharpVector(hit.point), new SVector3 { X = 10, Y = 10, Z = 10 }); for (int i = 0; i < crowd.GetAgentCount(); ++i) { NavPoint targetPt; navMeshQuery.FindRandomPointAroundCircle(ref newPt, 3, out targetPt); Debug.Log($"agent{i} : x {targetPt.Position.X}, y {targetPt.Position.Y}, z {targetPt.Position.Z}"); crowd.GetAgent(i).RequestMoveTarget(targetPt.Polygon, targetPt.Position); } crowd.UpdateMoveRequest(); } // RayCast } // Mouse Click } }