And lets start with the base of our blob: The Verlet implementation.
I can't really explain what is verlet, it's simply the best (and easiest) way to simulate real movements in computer. It may look simple, but is very powerful!
And here's the Flash version of it:
- function verlet(particle){
- with(particle){
- if(oldx == undefined or oldy == undefined){
- oldx = _x;
- oldy = _y;
- }
- tempx = _x;
- tempy = _y;
- _x = _x + (_x - oldx);
- _y = _y + (_y - oldy);
- oldx = tempx;
- oldy = tempy;
- }
- }
It may looks quite simple, but is not! It works this way:
2: It calls the particle and amkes the particle execute the following code
3, 4, 5: It checks whether the two variables (oldx,oldy) exists, if not, create them
8, 9: Stores the current position in two temporary variables.
11, 12: Moves the particle based on the last position, that is, if last x position is 5, and current x position is 10, then calculates (10-5) and apply it
14, 15: Now store the last position (before the last calculation) in the oldx and oldy variables.
See? Simple, hun? Now, lets test it! :D
_root.createEmptyMovieClip("verlet1",_root.getNextHighestDepth());
grav = .3;
verlet1._x = Stage.width/2;
verlet1._y = Stage.height/2;
verlet1.lineStyle(2,0,100);
verlet1.beginFill(0xFF0000,100);
verlet1.moveTo(-15,-15);
verlet1.lineTo(-15,15);
verlet1.lineTo(15,15);
verlet1.lineTo(15,-15);
verlet1.lineTo(-15,-15);
verlet1.endFill();
function onEnterFrame(){
verlet(verlet1);
verlet1._y += _root.grav;
}
function verlet(particle){
with(particle){
if(oldx == undefined or oldy == undefined){
oldx = _x;
oldy = _y;
}
tempx = _x;
tempy = _y;
_x = _x + (_x - oldx);
_y = _y + (_y - oldy);
oldx = tempx;
oldy = tempy;
}
}
Now, what you may see when paste and execute this code on Flash is a red box falling on the stage. Nothing more, but it may be more complex if implemented a constraint script.
This, and more, at the next part ;)
ViciousPud.WF.jpg)