
Welcome Guest
|
#1
|
||||
|
||||
|
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) {
// ....
} |
«
Previous Thread
|
Next Thread
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |





