Algorithm for Direction Change upon Collision
m_p_wilcox at yahoo.co.uk
Fri Nov 8 04:54:47 EST 2013
>> I know that I have to create a flag as a custom property saying “this puck’s already handled, don’t check it” to the intersect() function.
>> But no matter which path I chose to accomplish this, it became dead end.
The biggest problem here is that "finished colliding" is a property of a collision rather than any individual pucks. It gets really messy with multiple collisions.
>> Any quick ideas, anyone?
As you may have guessed, this isn't an uncommon problem. A couple of ways of handling this off the top of my head:
1) If your pucks are circles you should be figuring out the vector between the centre of the circles when they intersect as part of working out the correct bounce angle. If you have this vector then you can also work out whether the current direction of each puck is taking it towards or away from the one it is colliding with and act accordingly. This should handle the multiple collision situation most graciously.
2) When two pucks collide, don't only change their velocities but also their positions, so that they are not overlapping. If you do this make sure you move both by half the overlapping distance (simple version), or proportional to their velocities (more realistic version). Obviously this involves moving both pucks from the one intersect test.
Hope that helps,
More information about the Use-livecode