Making Objects Ricochet
Posted on 2011-09-02
Hi, I have two object that I'd like to have ricochet when they collide. I can identify when they collide using the "object1.hitTestObject(object2)" command, but how would I make them each go in opposite directions?
Right now I'm using the following to make them move in a sloped path:
object1.x = slopeX;
object1.y = slopeY;
Clearly, I can invert the slopes, but there has to be a more elegant approach (at least I would think...).
So, I was wondering if there is a better way to tell the object to travel in a path that is 180 degrees from its current path or in essence ricochet.