# Decelerating spring effect?

**URL:** <https://forum.kirupa.com/t/decelerating-spring-effect/38065>\
**Category:** Uncategorized\
**Created:** [December 17, 2003, 9:49pm UTC](https://forum.kirupa.com/t/decelerating-spring-effect/38065 "2003-12-17T21:49:17Z")\
**Posts on this page:** 4\
**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/38065/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!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 23, 2003, 4:20am UTC](https://forum.kirupa.com/t/decelerating-spring-effect/38065/2 "2003-12-23T04:20:25Z")

</div>

not too difficult  
you just have to set movetype =“spring” on the way out and  
= “decel” on the way back  
[AS]  
// my spring effect -

onClipEvent (load) {  
this.\_y = 200;  
this.\_x = 100;  
targetX = 300;  
mover = 0;  
loop = 0;

movedx = 0;  
targetX = 300;  
}  
onClipEvent (enterFrame) {  
if ( movetype == “spring” ){

if (\_root.go == 1) {  
mover = mover+(targetX-this.\_x)/2;  
mover=mover \*.6;  
this.\_x = this.\_x+mover;  
loop=loop+1;  
\_root.where=\_x;  
}

}  
else if (movetype==“decel”){  
distX = targetX-this.\_x;  
totalDistance = Math.sqrt(distX_distX);  
this.\_x += distX_speed;  
if (totalDistance\<1) {  
this.\_x = targetX;  
}  
}

}  
[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 23, 2003, 6:22am UTC](https://forum.kirupa.com/t/decelerating-spring-effect/38065/3 "2003-12-23T06:22:58Z")

</div>

or maybe try the spring tutorial found… OH WAIT! RIGHT HERE ON [KIRUPA.COM](http://KIRUPA.COM)!!! how nifty is that? 😉 (heres a link)

[http://www.kirupa.com/developer/actionscript/spring.htm](http://www.kirupa.com/developer/actionscript/spring.htm)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 23, 2003, 1:20pm UTC](https://forum.kirupa.com/t/decelerating-spring-effect/38065/4 "2003-12-23T13:20:28Z")

</div>

thanks everyone and merry christmas and happy new year - dont work too hard!
