collision detection movement

How can i set it up so if two objects are moving in the same direction and get close to each other once the collision detection is triggered i want each object to go in different directions, right now when two objects get close they go around in a circle if they went in different directions would be great