//----------------------------------------------------------------------------------- // when a decision about which direction to turn is necessary, // the choice is made based on which tile adjoining the intersection // will put the virus nearest to its target tile, measured in a straight line //----------------------------------------------------------------------------------- protected Direction directionToTarget(Vector3 target) { WaypointNode node = walker.getCurrentNode(); float bestDistance = float.MaxValue; Direction bestDirection = Direction.None; List <Direction> directions = allowedDirections(); foreach (Direction direction in directions) { Vector3 nextNodePosition = node.getAdjacent(direction).transform.position; Vector3 directionVector = (nextNodePosition - node.transform.position).normalized; Vector3 origin = node.transform.position + directionVector; float distance = topo.calculateDistance(origin, target); if (bestDistance > distance) { bestDistance = distance; bestDirection = direction; } } return(bestDirection); }
public void Update() { if (gameManager.paused || !gameManager.inGame) { return; } updateInput(); updateDirection(); if (atNextNode() && currentNode.twin != null) { currentNode = currentNode.twin; nextNode = currentNode.getAdjacent(currentDirection); if (nextNode == null) { nextNode = currentNode; currentDirection = Direction.None; } walkerBody.position = currentNode.transform.position; } updateMove(); update(); print(currentDirection); }