This concept is called "mens rea" or "guilty mind". A statute for each crime should define what type of mens rea it requires. As an example, generally murder requires an intent to kill or seriously injure someone. Manslaughter only requires a reckless disregard for whether or not you've harmed someone. However, some crimes do not have a mens rea requirement. They are usually minor, like speeding.
For a better explanation of mens rea, see this part of the linked site: http://lawcomic.net/guide/?p=173
EDIT: For an interesting example of when the mens rea requirements for a crime are unclear, see Elonis v. US: a free speech case involving intimidating speech posted to Facebook. http://www.scotusblog.com/case-files/cases/elonis-v-united-s...