A Flash Developer Resource Site

1. So, the purpose of using radius this way
Code:
```var radius1 = (clip1._width * clip1._width)/2
var radius2 = (clip2._width * clip2._width)/2```
Code:
```var radius1 = clip1._width/2
Is cos the first way you are taking the whole formula and making everyhting to the power of 2,
So, its faster cos you have to do this
Code:
```var radius1 = (clip1._width * clip1._width)/2
var radius2 = (clip2._width * clip2._width)/2```
Only once, out of each hitTest, instead of having an extra step to calculate the sqrt inside each test,right?
Clever, i wonder if this principle can be used in other things

2. I may be very dumb, cos i cant understand how you go from this
Code:
```var radius1 = clip1._width/2
To this
Code:
```var radius1 = (clip1._width * clip1._width)/2
var radius2 = (clip2._width * clip2._width)/2```
I mean, if its all to the power of 2, why its not
(clip1._width * clip1._width)/ 4
?
Or this power of 2 has nothing to do?

3. the radius of something is half its circumference

so if a ball has a radius of 10cm its circumference is 20cm

4. I know that, i dont understand the stuff necessary to drop the sqrt in the distance formula

5. I dont know if i made something wrong, but please look at this fla
With big clips,in this way
Code:
```var radius1 = (clip1._width * clip1._width)/2;
var radius2 = (clip2._width * clip2._width)/2;
the test start to gives true without them to touch eah other,but this
Code:
```var radius1 = clip1._width/2;
dont

6. Originally Posted by mr_malee
the radius of something is half its circumference

so if a ball has a radius of 10cm its circumference is 20cm
WRONG. It's half the diameter.

7. we all make mistakes

8. What's a circumference?

9. the distance around a circle

10. Ah, ok

11. Why dont you answer me?

12. Since noone bother in makes things clear, i am beginning to think there is no such thing as circle hitTest without sqrt, cos this way has a bug
Code:
```var radius1 = (clip1._width * clip1._width)/2;
var radius2 = (clip2._width * clip2._width)/2;
But this dont
Code:
```var radius1 = clip1._width/2;
BUT this way is difficult to use cos you cant calculate the summ of the two radius before any test, cos you dont know what are you going to test, unless you pre calculate all the possible combinations before any hitTest, but with many clips this may be very dificult, and even if more clips are added dynamically?

13. create a circleToCircle hitTest function which accepts two circles and find the radius like that.

14. Circle to circle collision without a square root is very easy.

function checkCollision(circle1, circle2) {
xdist = circle2._x-circle1._x;
ydist = circle2._y-circle1._y;
}

15. But what is the advantage in drop the sqrt this way since you have to add the stuff to calculate the power of the radius of the circle?
I mean, take out one thing and add another
OR do you mean that calculate this power stuff is faster them to calculate some sqrt?

16. Well, lemme put it this way:the radius of the balls will never change, so you can precalculate the square of their radii, but the x and y distances will be changing constantly.

17. thats an interesting way to do circle to circle vengeance, good to know

18. Originally Posted by VENGEANCE MX
Well, lemme put it this way:the radius of the balls will never change, so you can precalculate the square of their radii,
Still didnt get it
The way i see, even if you have the two pre calculated sqrt radius, the distance should be compared to the sqrt of the sum of the two radius, not to the sqrt of one radius plus the sqrt of the another
I mean, sqrt(a + b) its not the same as sqrt(a) + sqrt(b),and so as (a+b)*(a+b) too

19. FASTER HITTEST FOR DOING TONS OF HIT DETECTION FOR PLATFORMS + PHYSICS

see www.spiritonin.com/radius - to see example in action

When doing a platform based game where you are checking collision on lots of blocks, I found it is much faster to do the hitTest(x,y,true) on the movieclip containing all the blocks, than it is to do a mc.hitTest(mc) on every block.

Problem is I have a bunch of physics stuff based on individual block detection.

I tried a method that I think is faster:

You do Two MC's in the same coordinates in the same timeline - "world"(contains all the blocks) and "worldEdges"(contains dynamically created blocks that are a certain amount larger than the "world" blocks, creating an edge around all of them visually You will see this in the game if you look at the example)

The amount larger is based on the size of your sprites, where the size should be a few pixels larger than half the width of the widest sprite (so if you are doing 32x32 sprites, make the edges ~20 pixels wider in each direction) so if you have a 50wx100h block, it should spawn a 90wx140h block that is 20 pixels up and left of the collision block, but in the "worldEdge" mc

Then when you do the hitest you check to see if the center point of the sprites is hitting "worldEdge" then if it is you check collsion on each platfrom in "world".

If you have different sized sprites, you can create more edge clips ("worldEdgeBig", "WorldEdgeMedium" etc...)

You can also do it for different types of platforms or platform groups to cut down on the number of MC's being tested when an edge is penetrated.

Hope that makes sense... It was a bit messy to set up, but the collision seems to work a lot cheaper especially with lots of enemies bouncing around the screen.

If anyone knows a faster way to check a complex set of block for detection, leg me know.

20. It was also recently proven by several of us that for AS3 at least, circle-to-circle collision detection (without the sqrt call) is significantly faster then anything else. The results are outlined in this thread along with sample code:

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap