yay! I've solved my own problem! I created a Creat->Measure Tools->Distance Tool. This creates a tool that has two locators and measures the distance between them. I named one startLocator and the other endLocator. I connected the location of the startLocator to the location of the camera, so it will move with the camera. Then I put the endLocator and the part I want to be in focus (the f-stop value determines how much in front and behind the focus distance will be in focus. f:5.6 means a small distance, wher f:64 means practically everything is in focus). Then I connected the camera's focus distance to the Distance Tool's distance attribute. I had to do this in the script editor cause I couldn't find the options in the connection editor.
connectAttr -f distanceDimension1.distance cameraShape1.focusDistance;
And now it works. Yay!