
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) {
// ....
} |
|
#2
|
||||
|
||||
|
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
|
||||
|
||||
|
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.
__________________
Twitter . |
«
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 |



Twitter
