Algorithm for Direction Change upon Collision

Mark Wilcox m_p_wilcox at yahoo.co.uk
Sat Nov 9 02:45:55 EST 2013


If you're looking for performance in your physics then you really want to avoid using cos(), sin(), atan() etc as far as possible. Instead look at vector math - e.g. you can use the dot product to get to the cosine of the angle between two vectors directly. It's also worth avoiding square roots if you don't need them, e.g. if your pucks all have the same radius then rather than check collisions by comparing the distance between them to the diameter of one, compare the distance squared (which doesn't require a square root) to the diameter squared.

When LiveCode gets Box2d you'll benefit from all of this kind of optimisation already being done and the calculations happening in native code.

Mark


More information about the use-livecode mailing list