protected Vector2Int RandomWalk() { Vector2Int randomPos = new Vector2Int(0, 0); // Loop until a traversable straight line is found // It must not pass an obstacle and it must not be out of bounds. // This might cause problems if an agent is surrounded by obstacles, for instance // In that case: do something more intelligent. while (true) { Vector2 randomWalk = Random.insideUnitCircle * Random.Range(0, maxRandomWalkDistance); randomPos = grid.WorldToGrid(transform.position + new Vector3(randomWalk.x, 0, randomWalk.y)); // Ignore out of bound positions if (!grid.InBounds(randomPos)) { continue; } // Ignore obstacles RaycastHit hit; if (Physics.Raycast(transform.position, new Vector3(randomWalk.x, 0, randomWalk.y), out hit, randomWalk.magnitude, LayerMask.GetMask("Obstacles"))) { continue; } else if (obstacleHeightMap.GetHeight(randomPos.x, randomPos.y) > 0) { continue; } break; } return(randomPos); }
public float GetInfluence(Vector3 point) { Vector2Int pos = grid.WorldToGrid(point); if (!grid.InBounds(pos)) { return(0); } return(GetInfluence(pos.x, pos.y)); }