/** * Warp into the scene on the nav mesh, finding the nearest cell. The currentCell and position3d * are updated and this new position is returned. This updates the state of the path finder! * * @return the new position in the nearest cell */ public Vector3f warp(Vector3f newPos) { Vector3f newPos2d = new Vector3f(newPos.x, 0, newPos.z); currentCell = navMesh.findClosestCell(newPos2d); currentPos3d.set(navMesh.snapPointToCell(currentCell, newPos2d)); currentPos3d.setY(newPos.getY()); currentPos.set(currentPos3d.getX(), currentPos3d.getZ()); return currentPos3d; }
/** * Generate a new Path from the currentPos3d to the supplied goal position. setPosition() must be * called first for this to work. If the point is not in the mesh, false is returned. You should * use warp() in that case to place the point in the mesh. * * @return fail if no path found or start location outside of a cell */ public boolean computePath(Vector3f goal, DebugInfo debugInfo) { // get the cell that this point is in Vector3f newPos2d = new Vector3f(currentPos3d.x, 0, currentPos3d.z); currentCell = navMesh.findClosestCell(newPos2d); if (currentCell == null) { return false; } goalPos3d = goal; goalPos = new Vector2f(goalPos3d.getX(), goalPos3d.getZ()); Vector3f goalPos2d = new Vector3f(goalPos.getX(), 0, goalPos.getY()); goalCell = navMesh.findClosestCell(goalPos2d); boolean result = buildNavigationPath( path, currentCell, currentPos3d, goalCell, goalPos3d, entityRadius, debugInfo); if (!result) { goalPos = null; goalCell = null; return false; } nextWaypoint = path.getFirst(); return true; }
/** * Get the nearest cell to the supplied position and place the returned position in that cell. * * @param position to place in the nearest cell * @return the position in the cell */ public Vector3f warpInside(Vector3f position) { Vector3f newPos2d = new Vector3f(position.x, 0, position.z); Cell cell = navMesh.findClosestCell(newPos2d); position.set(navMesh.snapPointToCell(cell, newPos2d)); return position; }