PDA

View Full Version : A Lil Scripting Help


Damaso
08-18-2003, 01:28 PM
I've been playing the swishmax demo I got from swishzone.com (http://www.swishzone.com/max_swi/demolisher.swf) called demolisher.swi. Any of you who are familiar with this maybe you can help me out. I'm no scripting intermediate nor expert, to this extent I teach myself by analyzing and experimenting. On the demolisher.swi, I wanted the "Ball" which is hanging from a "Hanger" to be steady (not swinging) when the movie starts. And when the "Hanger" is dragged and moved, the "Ball" should swing until it stop after a few swing, like a pendulum. I tried to chage some value and variable, but I still can't get it to work. :unsure:

Scene_1 code
function sqrt(val) {
   i = 0;
   x = 1;
&nbsp; &nbsp;while (i < 20) {
&nbsp; &nbsp; &nbsp; &nbsp;x = x - ((x * x - val) / (2 * x));
&nbsp; &nbsp; &nbsp; &nbsp;i += 1;
&nbsp; &nbsp;}
&nbsp; &nbsp;sqrt = (1000 * x) / 1000;
&nbsp; &nbsp;return sqrt;
}

Demolisher sprite code
onFrame (1) {
&nbsp; &nbsp;normalDist = 100;
&nbsp; &nbsp;elasticity = 0.7;
&nbsp; &nbsp;dampness = 0.00;
&nbsp; &nbsp;gravity = 0.1;
&nbsp; &nbsp;velX = 0.0;
&nbsp; &nbsp;velY = 0.0;
&nbsp; &nbsp;accelX = 0.0;
&nbsp; &nbsp;accelY = 0.0;
&nbsp; &nbsp;time = 5;
}
onFrame (2) {
&nbsp; &nbsp;distX = Hanger._X - Ball._X;
&nbsp; &nbsp;distY = Hanger._Y - Ball._Y;
&nbsp; &nbsp;currentDist = _root.sqrt(distX * distX + distY * distY);
&nbsp; &nbsp;accell = ((currentDist - normalDist) * elasticity) / normalDist;
&nbsp; &nbsp;accellX = accell * distX / currentDist;
&nbsp; &nbsp;accellY = ((accell * distY) / currentDist) + gravity;
&nbsp; &nbsp;velX += (accellX -(dampness * velX)) * time;
&nbsp; &nbsp;velY += (accellY -(dampness * velY)) * time;
&nbsp; &nbsp;trace(accellY);
&nbsp; &nbsp;trace(dampness * velY);
&nbsp; &nbsp;trace(time);
&nbsp; &nbsp;trace(velY);
&nbsp; &nbsp;Ball._X += velX * time;
&nbsp; &nbsp;Ball._Y += velY * time;
&nbsp; &nbsp;dot1._X = Hanger._X * 0.2 + Ball._X * 0.8;
&nbsp; &nbsp;dot1._Y = Hanger._Y * 0.2 + Ball._Y * 0.8;
&nbsp; &nbsp;dot2._X = Hanger._X * 0.4 + Ball._X * 0.6;
&nbsp; &nbsp;dot2._Y = Hanger._Y * 0.4 + Ball._Y * 0.6;
&nbsp; &nbsp;dot3._X = Hanger._X * 0.6 + Ball._X * 0.4;
&nbsp; &nbsp;dot3._Y = Hanger._Y * 0.6 + Ball._Y * 0.4;
&nbsp; &nbsp;dot4._X = Hanger._X * 0.8 + Ball._X * 0.2;
&nbsp; &nbsp;dot4._Y = Hanger._Y * 0.8 + Ball._Y * 0.2;
}
onFrame (3) {
&nbsp; &nbsp;gotoAndPlay(2);
}

dammitjanet
08-18-2003, 03:10 PM
&nbsp; &nbsp;elasticity = 0.5;
&nbsp; &nbsp;dampness = 0.01;
&nbsp; &nbsp;gravity = 0.03;

you need to play around with the following 3 values:

elasticity 0.0-1.0 ... values between 0.5 and 0.7 give best bouncyness to the ball, but as you got to 0.7, dampening needs to increase

dampness - 0.00 - 0.03 ... very low values seem to work best here, 0 means no damping (the default) anything larger than 0.03 can mean bouncing not working correctly

gravity - 0.00 -0.10 ... very small values agian best here, I found 0.03 to be about right.