Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#Actualjjd

Posted 23 July 2013 - 07:29 AM

This tutorial explains the mathematics behind collision detection using bounding circle method. Source code and online demo is available with the tutorial.

 

Bounding Circle collision detection: KineticJS/HTML5 Tutorial

 

Just a suggestion: get rid of the sqrt operation. It is slow and unnecessary. The same test can be expressed as,

var sum_radii = sprite1Radius + sprite2Radius;
var sum_radii_sqr = sum_radii * sum_radii;

var dist_sqr = (distanceX * distanceX) + (distanceY * distanceY);

return dist_sqr <= sum_radii_sqr

-Josh


#1jjd

Posted 23 July 2013 - 07:28 AM

This tutorial explains the mathematics behind collision detection using bounding circle method. Source code and online demo is available with the tutorial.

 

Bounding Circle collision detection: KineticJS/HTML5 Tutorial

 

Just a suggestion: get rid of the sqrt operation. It is slow and unnecessary. The same test can be expressed as,

var sum_radii = sprite1Radius + sprite2Radius;
var sum_radii_sqr = sum_radii * sum_radii;

var dist_sqr = (distanceX * distanceX) + (distanceY * distanceY);

return dist_sqr <= sum_radii_sqr

-Josh


PARTNERS