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




 
 
Thread Tools Display Modes
  #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) {
   // ....
}
  #2  
Old 02-05-2006, 06:17 PM
saumya's Avatar
saumya saumya is offline
Super Moderator
 
Join Date: Oct 2004
Location: India
Posts: 2,214
Rep Power: 11
saumya is on a distinguished road
The math method is more accurate and where as the hittest is not when you are tryign to hittest two objects.Because we can only hittest one object with another x,y co-ordinate.But with math method we can verywell add another formula, which will calculate the distance between the circumference of two circular objects.

well, regarding the difference in efficiency,I donot know exactly, but seems hittest will take up more memory,not sure though.
__________________
www.saumyaray.com
  #3  
Old 03-26-2006, 03:55 AM
FlashMove's Avatar
FlashMove FlashMove is offline

FlashMove Master
 
Join Date: Jan 2000
Location: Singapore
Posts: 4,597
Rep Power: 10
FlashMove is on a distinguished road
The math collision detection method is a more efficient and accurate method. The flash hitTest method does a pixel collision detection which increases in overhead when your hitTest area get bigger, the object has more pixels to detect.
__________________
Actionscript tag . Donate Here . Testimonial . Join Flash Chat UserGroup . Twitter . Facebook
 


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 06:09 AM.