public override void OnInspectorGUI() { DrawDefaultInspector(); CorvoPathFinder myScript = (CorvoPathFinder)target; if (GUILayout.Button("Test grid build")) { myScript.generateGrid(true); } if (GUILayout.Button("Find Path")) { myScript.clearPath(); if (myScript.testPathDestination) { myScript.findPath(myScript.testPathDestination.position); } else { Debug.LogError("Destination not assigned!"); } } if (GUILayout.Button("Clear")) { myScript.forceStop(); } }
public void addNearNode(GridNode _node) { CorvoPathFinder.TestVector(_node); GridNode[] _temp = new GridNode[nearNodes.Length + 1]; for (int _x = 0; _x < nearNodes.Length; _x++) { _temp[_x] = nearNodes[_x]; } _temp[_temp.Length - 1] = _node;//nodo aggiunto nearNodes = _temp; }
public NPCMover(SceneNPC awholeNPC, UnitPathfinder aPathFinder, CorvoPathFinder aCorvoPathFinder) { _distanceCalcTimer = 0; _walkTarget = Vector3.zero; _isWalkTargetSet = false; _lookDirection = Quaternion.identity; pathFinder = aPathFinder; corvoPathFinder = aCorvoPathFinder; _firstUpdate = true; _wholeNPC = awholeNPC; }
void FixedUpdate() { CorvoPathFinder pf = GetComponent <CorvoPathFinder>(); if (destinationActive) { if (pf) { if (pf.havePath()) { checkReachedNode(); } if (Time.time > pathRefreshTime) { updatePath(); } if (mustMove) { if (pf.havePath()) { Vector3 _dir = (pf.getDestination() - transform.position).normalized; if (updateRotation != rotationType.dontRotate) { Vector3 _dir2D; if (updateRotation == rotationType.rotateAll) //rotate all { _dir2D = (pf.getDestination() - transform.position).normalized; } else //don't update z axis { _dir2D = ((pf.getDestination() - Vector3.up * pf.getDestination().y) - (transform.position - Vector3.up * transform.position.y)).normalized; } transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(_dir2D), Time.deltaTime * speed * 60); } transform.position = Vector3.MoveTowards(transform.position, pf.getDestination(), Time.deltaTime * speed); } } } else { Debug.LogError("No PathFinder Assigned! please assign component CorvopathFinder to this object.", gameObject); } } }