/* * void CreateNavMesh() * { * var data = new float[] * { * -0.510708f,0.000000f,0.560116f, * 0.475209f,0.000000f,0.560116f, * -0.510708f,0.000000f,0.223784f, * 0.475209f,0.000000f,0.223784f, * -0.510708f,0.000000f,0.560116f, * 0.475209f,0.000000f,0.560116f, * -0.498859f,0.000000f,1.604937f, * 0.487058f,0.000000f,1.604937f, * -0.503560f,0.000000f,2.655539f, * 0.482357f,0.000000f,2.655539f, * -0.487180f,-0.147305f,3.284405f, * 0.498737f,-0.147305f,3.284405f, * -1.871698f,0.041424f,2.636110f, * -1.855318f,-0.105881f,3.264977f, * -2.698119f,0.000962f,2.633322f, * -2.681739f,-0.146342f,3.262189f, * -1.869888f,0.000000f,2.081351f, * -2.696310f,0.000000f,2.078564f, * -1.867582f,0.000000f,1.374484f, * -2.694004f,0.000000f,1.371696f, * -1.863584f,0.000000f,0.200000f, * -2.690005f,0.000000f,0.145856f, * -1.834403f,0.000000f,-0.430380f, * -2.660824f,0.000000f,-0.430000f, * 0.496814f,-0.085523f,-1.081090f, * -0.502801f,0.000000f,-0.437349f, * -0.489103f,-0.085523f,-1.081090f, * 0.483116f,0.000000f,-0.437349f, * 0.511144f,-0.174994f,-1.754542f, * -0.474773f,-0.174994f,-1.754542f, * -1.334424f,-0.129101f,-1.093288f, * -1.320094f,-0.218572f,-1.766740f * }; * * int[] indexes = { 2, 3, 1, 1, 6, 2, 6, 7, 8, 7, 10, 8, 10, 11, 12, 9, 14, 11, 13, 16, 14, 15, 17, 18, 18, 19, 20, 20, 21, 22, 21, 24, 22, 23, 3, 26, 4, 26, 3, 28, 27, 26, 25, 30, 27, 30, 31, 27, 2, 4, 3, 1, 5, 6, 6, 5, 7, 7, 9, 10, 10, 9, 11, 9, 13, 14, 13, 15, 16, 15, 13, 17, 18, 17, 19, 20, 19, 21, 21, 23, 24, 23, 21, 3, 4, 28, 26, 28, 25, 27, 25, 29, 30, 30, 32, 31 }; * * var vertex = new Vertex3D[data.Length / 3]; * for (int i = 0; i < vertex.Length; i++) * { * var point = new Vector3(data[i * 3], data[i * 3 + 1], data[i * 3 + 2]) * 4; * point.Y = 0; * vertex[i] = new Vertex3D(point); * } * * for (int i = 0; i < indexes.Length; i++) * { * indexes[i] -= 1; * } * * mesh = new Mesh(vertex, indexes); * Materials = new Material[indexes.Length / 3]; * var shdrst = new ShaderSettings(); * shdrst.Ambient = true; * for (int i = 0; i < Materials.Length; i++) * { * Materials[i] = new MaterialPMX(shdrst, new RenderDirectives()); * Materials[i].Offset = i * 3; * Materials[i].Count = 3; * } * md = new MeshDrawer(mesh, Materials); * Node.AddComponent(md); * * * navMesh = new NavigationMesh(vertex, indexes); * var navList = navMesh.navigationCells.ToList(); * var cell1 = navMesh.GetCellFromPosition(new Vector3(0)); * var cell2 = navMesh.GetCellFromPosition(new Vector3(-1.0431f, 0, 1.53819f)); * } */ void MadePath(int start) { foreach (var mat in Materials) { mat.UniformManager.Set("ambient_color", Vector3.Zero); } int end = 25; //var searcher = new AStarSearch(navMesh); //var result = searcher.CalculatePath(navMesh.navigationCells[start].Center, navMesh.navigationCells[end].Center); var navAgent = new NavigationAgent(navMesh); var result = navAgent.SearchPath(navMesh.navigationCells[start].Center, navMesh.navigationCells[end].Center); if (result != null) { Console.WriteLine(result.Length); foreach (var waipoint in navAgent.pathMesh) { Materials[waipoint.Index].UniformManager.Set("ambient_color", Vector3.UnitY); // Console.WriteLine(waipoint.Index); } } Materials[start].UniformManager.Set("ambient_color", Vector3.UnitX); Materials[end].UniformManager.Set("ambient_color", Vector3.UnitZ); }
public MovementRangeRequest(Vector3 position, NavigationAgent agent, Action <Tile[]> callback) { //TODO: Chnage AgentRange this.position = position; this.callback = callback; this.agent = agent; }
private float ComputeCost(NavigationPoint navPoint, NavigationAgent agent) { var addCost = additionalCost == null ? 0 : additionalCost.Invoke(agent, navPoint.position); var neighboursCost = _computeNeightboursCost ? GetNeightboursCost(navPoint) : 0; return((PointIsVisibleFromPlayerPosition(navPoint) ? VISIBLE_BY_PLAYER - addCost : addCost) + neighboursCost); }
private void OnEnable() { m_NavAgent = gameObject.GetComponent<NavigationAgent>(); m_OriginalSpeed = m_NavAgent.Speed; m_Slowed = false; Slowdown(m_Slowed, 1.0f); }
public PathRequest(NavigationAgent agent, Vector3 startPosition, Vector3 endPosition, Action <Vector3[], int, bool> callback) { this.agent = agent; this.startPosition = startPosition; this.endPosition = endPosition; this.callback = callback; }
private void Start() { _tenantEvaluator = FindObjectOfType <TenantEvaluator>(); _tenantEvaluator.Add(this); _navigationAgent = GetComponent <NavigationAgent>(); this.transform.localScale = Vector3.zero; this.transform.DOScale(Vector3.one, .3f).SetEase(Ease.OutBack); }
public Vector3 FindNearestSafePoint(NavigationAgent agent) { var minCost = float.MaxValue; var minIndex = -1; var maxCost = float.MinValue; var maxIndex = -1; var nextPathPoint = Vector3.zero; if (_navigationType == NavigationType.ByUnityNavMeshPath) { agent.GetNearestPointToTarget(_player.position); } var beginPoint = GetNearestNavigationPoint(agent.transform.position); if (agent.TargetPoint != Vector3.negativeInfinity) { var prevTargetPoint = GetNearestNavigationPoint(agent.TargetPoint); minCost = EvaluateCost(prevTargetPoint, agent, nextPathPoint) + ComputeCost(prevTargetPoint, agent); minIndex = prevTargetPoint.index; } for (var i = -_computeAgentDistanceLimit; i <= _computeAgentDistanceLimit; i++) { for (var j = -_computeAgentDistanceLimit; j <= _computeAgentDistanceLimit; j++) { var index = beginPoint.index + i * height + j; if (index >= 0 && index < _navPoints.Length && beginPoint.index % height + j >= 0 && beginPoint.index % height + j < height && _navPoints[index].isPassable) { var cost = EvaluateCost(_navPoints[index], agent, nextPathPoint); if (cost < minCost) { cost += ComputeCost(_navPoints[index], agent); if (cost < minCost) { minCost = cost; minIndex = index; } if (cost > maxCost) { maxCost = cost; maxIndex = index; } } } } } if (minCost >= VISIBLE_BY_PLAYER)//if no safe area - run away from player { return(_navPoints[maxIndex].position); } return(_navPoints[minIndex].position); }
private float EvaluateCost(NavigationPoint navPoint, NavigationAgent agent, Vector3 nextPathPoint) { switch (_navigationType) { case NavigationType.ByUnityNavMeshPath: return(2 * Vector3.Distance(navPoint.position, agent.transform.position) + 3f * Vector3.Distance(navPoint.position, nextPathPoint) + 0.5f * Vector3.Distance(navPoint.position, _player.position)); case NavigationType.SimpleNearestPoint: default: return(1 * Vector3.Distance(navPoint.position, agent.transform.position) + 2f * Vector3.Distance(navPoint.position, _player.position)); } }
void Start() { //CreateNavMesh(); navMesh = NavigationMesh.GetInstance; navAgent = new NavigationAgent(navMesh); navAgent.AgentSize = .3f; try { CreateAnimationController(); } catch (Exception e) { Console.WriteLine(e.Message); } }
void Start() { instanceRobo = this; m_transform = transform; if (navAgent == null) { navAgent = m_transform.parent.GetComponent <NavigationAgent>(); } beforePosition = m_transform.position; m_animator = GetComponentInChildren <Animator>(); }
public float AdditionalCost(NavigationAgent currentAgent, Vector3 point) { var cost = 0f; for (var i = 0; i < _agents.Length; i++) { if (_agents[i].Id != currentAgent.Id) { var dist = Vector3.Distance(_agents[i].TargetPoint, point); if (dist < _minDistanceBetweenAgents) { cost += 100f * (_minDistanceBetweenAgents - dist) / _minDistanceBetweenAgents; } } } return(cost); }
protected virtual void Awake() { _navAgent = GetComponent <NavigationAgent>(); }
public void UnregisterAgent(NavigationAgent agent) { _agentsTmp.Remove(agent); _agents = _agentsTmp.ToArray(); }
public void RegisterAgent(NavigationAgent agent) { _agentsTmp.Add(agent); _agents = _agentsTmp.ToArray(); }
// Use this for initialization void Awake() { vehicle = gameObject.GetComponent <VehicleAgent>(); navigator = gameObject.GetComponent <NavigationAgent>(); }