A Flash Developer Resource Site

# Thread: malleable rigid polygonal physics?

1. ## malleable rigid polygonal physics?

I've been looking around and trying to figure out how to make a physics engine that can handle a lot of rigid polygons (not just squares or circles, polygons with an indefinite amount of sides) with rotation, rolling (or wobbling imperfect shapes) down slopes, ect.

I was trying to find an engine malleable enough that I could effectivly cut one of the polygons into two pieces, divided by a crooked (multiple points) line.

so, yeah, I was basically trying to piece together an engine wherein I could create walls and rocks and stuff that you could break into pieces... and break the pieces into pieces.

anyone have the stones (ha, pun.) to take on such a dilemma?

and if you cant help me with the breaking part, could you just help me with the rigid physics engine part?

thanks

2. Please try this code:
Code:
```this.createEmptyMovieClip("cnt",this.getNextHighestDepth());
cnt.lineStyle(2, 0xFF0000, 100, true, "none", "round", "miter", 1);
cnt.moveTo(100,200);
cnt.lineTo(150,100);
cnt.lineTo(250,50);
cnt.lineTo(350,75);
cnt.lineTo(400,200);
cnt.lineTo(300,300);
cnt.lineTo(200,300);
cnt.lineTo(100,200);```
I know only this much.

3. You can draw various shapes by pressing and dragging the mouse.
Code:
```drw=false;
this.createEmptyMovieClip("cnt",10);
cnt.onMouseDown=function() {
if(_xmouse>0&&_ymouse>0&&_ymouse<400)drw=true;
lastx=_xmouse;
lasty=_ymouse;
}
cnt.onMouseUp=function() {
drw=false;
}
cnt.onMouseMove=function() {
if(drw){
thisx = _xmouse;
thisy = _ymouse;
cnt.lineStyle(3, 0xFF0000, 100);
cnt.moveTo(lastx,lasty);
cnt.lineTo(thisx,thisy);
lastx=thisx;
lasty=thisy;
}
}
stop();```

4. My recommendation would be to go with an existing engine (Fisix comes to mind but there are others and they might suit your needs better).
The easiest way to get the cracking of objects you're talking about is most likely to just destroy the old object and create new objects that look like they would fit together along a crack. That will take a bit of fancy coding -- figuring out exactly how to draw the resulting pieces, for example -- but I'm pretty sure that's unavoidable with the problem you have.
I left this fairly brief, so let me know if you want any more help.

Neal

5. I can tell you right off the bat that what you want will be really pushing the limits of flash.

I would personally suggest using an R-tree and the separating axis theorem. You will have to fake breaking objects apart.
Alternatively, you could use an R-tree, points and breakable springs (springs that are removed when they stretch too far). It would feel springy, but would look more impressive.

All in all, physics is an extremely complicated subject. Just getting an efficient r-tree working will be difficult.

6. Even a few dozen 3D polygons with attenuated lighting, 6DOF, a basic midpoint integrator, separating axis theorem for collision detection will crush the flash player. Let alone blowing things apart.

But if you would like to challange yourself then I would start looking at collision detection FIRST, this is the bottle neck of all physics engines. SAT is pretty effective and simple for polygon meshes but not enough by itself, early outs in your collision detection routine will be important in maintaining any sort of real-time frame rate, perhaps the most effective is using the estimated time of impact.

But really I would suggest something other than Flash ... unless you have no other choice ...

7. Originally Posted by shipstern
Even a few dozen 3D polygons with attenuated lighting, 6DOF, a basic midpoint integrator, separating axis theorem for collision detection will crush the flash player. Let alone blowing things apart.

But if you would like to challange yourself then I would start looking at collision detection FIRST, this is the bottle neck of all physics engines. SAT is pretty effective and simple for polygon meshes but not enough by itself, early outs in your collision detection routine will be important in maintaining any sort of real-time frame rate, perhaps the most effective is using the estimated time of impact.

But really I would suggest something other than Flash ... unless you have no other choice ...
I didn't notice anything in bug's message that said it had to be 3d. I'm pretty sure you're over thinking it.

8. Originally Posted by shipstern
SAT is pretty effective and simple for polygon meshes but not enough by itself, early outs in your collision detection routine will be important in maintaining any sort of real-time frame rate.
Hence the R-tree. I can see flash 9 taking ~30 polygons.

9. Yes on second thought your right I was over thinking it.

Just use an inefficient r-tree some SAT and Flash 9... I am sure you will have no problems getting things in your engine to break apart or "blowing up" with a bit of the right fancy coding.

you may find some interesting information here ... but you would have to dumb down the concepts as they are a little over thought for the Flash environment ... still a good read though and will give you a taste of what to look forward to and links to many pertinent papers that have actually been implemented by programmers who "have the stones".

http://www.continuousphysics.com/Bul...pBB2/index.php

#### 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

Click Here to Expand Forum to Full Width