LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 




 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-03-2006, 04:53 PM
gvDan's Avatar
gvDan gvDan is offline
Registered User
 
Join Date: Dec 2004
Location: US
Posts: 368
Rep Power: 9
gvDan is on a distinguished road
Sphere Collision Detection efficiency

The question here is regarding the difference in efficiency between two methods of calculating collision of an object with a sphere: hitTest( ), and some simple math.

The question has arisen purely from doubt as to what happens at the core of the hitTest method. [ I know this is somewhat trivial, but if it really makes a difference then I guess it's worth discussing. ]

Actionscript:
//  sphereMC -   for this example, it is a FILLED sphere, to insure that hitTest detects the object
//  myObject is simply a point.

//  1)  hitTest( ... )
if (  sphereMC.hitTest( myObject._x, myObject._y, true ) {
     // ....
}

//  - - - - - - - - - - - - - - -
//  2)  simple math
//  
radius = sphereMC._width/2;
dx = myObject._x - sphereMC._x;
dy = myObject._y - sphereMC._y;
distance = Math.sqrt(dx*dx + dy*dy);
if (distance < radius) {
   // ....
}
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Collision detection kombucha Newbies 4 03-05-2006 11:39 AM
Resolved: collision detection problem lukemack Flash MX ActionScript 1 05-20-2004 03:08 PM
Collision detection on multiple objects gs0uL Flash MX 1 11-19-2003 06:08 PM
Frame Independent Collision Detection Canstein33 Flash MX ActionScript 2 04-18-2003 06:10 PM
Collision Detection Picklestick Man Flash 5 Actionscript 2 04-08-2001 03:49 PM




All times are GMT. The time now is 10:25 PM.