# Decelerating spring effect?

**URL:** <https://forum.kirupa.com/t/decelerating-spring-effect/97109>\
**Category:** Uncategorized\
**Created:** [December 17, 2003, 9:49pm UTC](https://forum.kirupa.com/t/decelerating-spring-effect/97109 "2003-12-17T21:49:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![joecastro](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@joecastro](https://forum.kirupa.com/u/joecastro)\
**Post date:** [December 17, 2003, 9:49pm UTC](https://forum.kirupa.com/t/decelerating-spring-effect/97109/1 "2003-12-17T21:49:17Z")

</div>

does anybody know how to make a decelerating spring effect? what i want is to have a ball that goes to a target using the spring effect (ie it goes a bit further than the target and springs back a bit before a few times decreasing each time the distance - giving a spring effect) - but what i also want is that as it goes to the first position where it ‘springs’ back for the ball to decelerate!

I can do the spring - i can do the deceleration - but I dont know how to do the 2 together - :h:

// my spring effect -

onClipEvent (load) {  
this.\_y = 200;  
this.\_x = 100;  
targetX = 300;  
mover = 0;  
loop = 0;  
}  
onClipEvent (enterFrame) {  
if (\_root.go == 1) {  
mover = mover+(targetX-this.\_x)/2;  
mover=mover \*.6;  
this.\_x = this.\_x+mover;  
loop=loop+1;  
\_root.where=\_x;  
}  
}

// my deceleration

onClipEvent (load) {  
movedx = 0;  
targetX = 300;  
}

onClipEvent (enterFrame) {  
distX = targetX-this.\_x;  
totalDistance = Math.sqrt(distX_distX);  
this.\_x += distX_speed;  
if (totalDistance\<1) {  
this.\_x = targetX;  
}  
}

Any help much appreciated!
