Just reasearch collision detection, theres a topic all the way at the top of this forum thats loaded with awsome links.