code: public static double getDistanceTo(ShanksSimulation simulation,
              PercipientShanksAgent agent, Object o) {
          Location agentLocation = agent.getCurrentLocation();
          if (agentLocation.is3DLocation()) {
              try {
                  ContinuousPortrayal3D devicesPortrayal = (ContinuousPortrayal3D) simulation
                          .getScenarioPortrayal().getPortrayals()
                          .get(Scenario3DPortrayal.MAIN_DISPLAY_ID)
                          .get(ScenarioPortrayal.DEVICES_PORTRAYAL);
                  Continuous3D devicesField = (Continuous3D) devicesPortrayal
                          .getField();
                  Double3D objectLocation = devicesField
                          .getObjectLocationAsDouble3D(o);
                  return agentLocation.getLocation3D().distance(objectLocation);
              } catch (DuplicatedPortrayalIDException e) {
                  e.printStackTrace();
              } catch (ScenarioNotFoundException e) {
                  e.printStackTrace();
              } catch (ShanksException e) {
                  e.printStackTrace();
              }
          }
          if (agentLocation.is2DLocation()) {
              try {
                  ContinuousPortrayal2D devicesPortrayal = (ContinuousPortrayal2D) simulation
                          .getScenarioPortrayal().getPortrayals()
                          .get(Scenario2DPortrayal.MAIN_DISPLAY_ID)
                          .get(ScenarioPortrayal.DEVICES_PORTRAYAL);
                  Continuous2D devicesField = (Continuous2D) devicesPortrayal
                          .getField();
                  Double2D objectLocation = devicesField.getObjectLocation(o);
                  return agentLocation.getLocation2D().distance(objectLocation);
              } catch (DuplicatedPortrayalIDException e) {
                  e.printStackTrace();
              } catch (ScenarioNotFoundException e) {
                  e.printStackTrace();
              } catch (ShanksException e) {
                  e.printStackTrace();
              }
          }
          return Double.MAX_VALUE;
      }
docs: Get the distance from the agent to an object in the simulation
  
  @param simulation
  @param agent
  @param o
  object to measure the distance between the agent and the
  object
  @return the distance