Quantunet.com

My Account

Joins Us
Flash 8 Actionscript 2.0 Knowledgebase
2D Elastic Motion Multiple Forces  


Download .fla

Actionscript

var k:Number = 0.1;
var f:Number = 0.89;
var vx:Number = 0;
var vy:Number = 0;

pin1_mc.onPress = drag;
pin2_mc.onPress = drag;
pin3_mc.onPress = drag;
pin1_mc.onRelease = onReleaseOutside = enddrag;
pin2_mc.onRelease = onReleaseOutside = enddrag;
pin3_mc.onRelease = onReleaseOutside = enddrag;

onEnterFrame = function() {

distx = (pin1_mc._x - ball_mc._x)+(pin2_mc._x - ball_mc._x)+(pin3_mc._x - ball_mc._x);
disty = (pin1_mc._y - ball_mc._y)+(pin2_mc._y - ball_mc._y)+(pin3_mc._y - ball_mc._y);

vx = vx*f + distx*k;
vy = vy*f + disty*k;

ball_mc._x += vx;
ball_mc._y += vy;

clear();
lineStyle(1,0x999999,100);
moveTo(pin1_mc._x,pin1_mc._y);
lineTo(ball_mc._x,ball_mc._y);
moveTo(pin2_mc._x,pin2_mc._y);
lineTo(ball_mc._x,ball_mc._y);
moveTo(pin3_mc._x,pin3_mc._y);
lineTo(ball_mc._x,ball_mc._y);
updateAfterEvent();
};

function drag(){
this.startDrag();
}
function enddrag(){
this.stopDrag();
}


How The Actionscript Works

Note:
In physics forces are additive.


© 2008 Quantunet LLC All Rights Reserved | Intellectual Property | Terms of Use | Privacy
Home | About Quantunet | FAQ's | Contact Us