P
ROTOTYPE
I'm Not Only The Prototype, I'm Also A Member.
home
▪
stats
▪
search
▪
linkback
▪
about
▪
FAQ
| user: guest,
login
,
register
Movieclip
:
Spring behavior [ Hooke's Law ]
author:
mga
[+]
,
Submitted: 06.18.02 12p
• Last Edit: 12.12.06 9a
Avg. Rating: 5
// moves a MC to (xf,yf) oscillating like a spring // based on Hooke's Law with damping constant // k = spring constant // c = damping constant MovieClip.prototype.resorte = function (k, c, xf, yf) { var yo_mc = this; var deltax = 0; var vx = 0; var ax = 0; var deltay = 0; var vy = 0; var ay = 0; yo_mc.onEnterFrame = function () { deltax = xf - yo_mc._x; ax = -k * deltax; vx = c * vx + ax; yo_mc._x = yo_mc._x - vx; deltay = yf - yo_mc._y; ay = -k * deltay; vy = c * vy + ay; yo_mc._y = yo_mc._y - vy; if (xf == yo_mc._x && yf == yo_mc._y && ax < 0.1 && ay < 0.1) { delete (yo_mc.onEnterFrame); } }; };
usage
// this will move yourclip_mc from its current // position to 500,300 bouncing along the line yourclip_mc.resorte (.99, .8, 500, 300); // try different values for k and c // more FPS give smoother animation // hope you find it useful // mga
msg
1
{
assalto
[+]
, posted: 03.29.07 9a•-, top
[^]
}
\o/ - NICE!!!!
cool effect, nice and very customizable easing!
tanx for this!
Add Comment
[+]
›opyleft 2001-2010. Layer51 is: Jaime Prado.
@