Javascript Physics Engine 2

I have now made an update to my physics engine. I have put in some basic collision detection which is rectangles only so far so there will be no circles in sight this time. The balls change colour when they collide, I put this in for debugging and I thought it looked pretty so i haven’t bother to remove it from the display.js file.

Also there are different size square now (rectangles also work but I prefer squares). Also they actually bounce off the right hand wall rather than bouncing off something just past the right hand wall. In my example there is no check to see if the squares overlap at the start and the collision detection can’t handle the big overlap so if you get this refresh the page and hope you don’t get an overlap.

At the moment the collision detection is fairly crude because it just handles rectangle to rectangle. I have planned out a few algorithms for circle-circle collision and more advance square-square collision which should work with rotated square.

If you come across any bugs please tell me. I have found some bugs that have been quite rare when I was testing before (one happened when the squares collided so that the corners hit each other) so I may bot have picked some of them up.

http://www.quantumstate.co.uk/physics/physics2/

Leave a Reply