The player moves a spell object, the spell must stay withing a certain range of the player. The spell is moved using a physics system and it has mass and velocity. Currently when the spell goes out of range of the player it's being moved back into range, this has the effect stopping the spell abruptly at the edge. I want to smooth out this abrupt stop so that it gradually slows down. I tried to apply an easing function but because the time and distance change every frame I couldn't figure out the formula.

Is there some sort of physics or easing formula I can use to gradually slow down the spell before it gets to the edge of its range, while at the same time guaranteeing that it never leaves the range?

Additional Info:

The spells range is a circle. I only care about the center of the spell object. Movement forces are continually being applied to the spell.

  • 1
    \$\begingroup\$ Why not use a spring? Or apply a corrective force that linearly increases with the error (distance away from max distance) though both these methods might over-react. \$\endgroup\$
    – Roy T.
    Commented May 9, 2014 at 9:25
  • \$\begingroup\$ You want deacceleration. \$\endgroup\$ Commented May 9, 2014 at 12:24
  • \$\begingroup\$ @RoyT. I want to apply a corrective force, but I am looking for a formula to specify how much force so that the spell wont slam into the wall. The spell can have different masses so it's hard to just hack something in. \$\endgroup\$
    – Ian Hern
    Commented May 9, 2014 at 16:13
  • \$\begingroup\$ I would use a tween. I could give you the formula if you didn't already accept your own answer. \$\endgroup\$
    – badweasel
    Commented May 10, 2014 at 5:04

1 Answer 1


I ended up doing the following and it works all right. First I use F = m(dv/dt) to calculate the force that would stop the spell moving completely. Then I take the time until the spell exits the range at it's current velocity, if it will exit in under 0.05 seconds then I apply the stopping force, but scale it depending on how soon it will exit (the minimum being 1 game tick worth of time). I.E. if the spell will leave the range in one game tick or less then we apply the full stopping force, if it will take more than 0.05 seconds to leave the range then we do nothing, in-between those two extremes we just scale the force from 100% down to 0%. This creates a nice deceleration effect, while guaranteeing that that spell will not leave the range.

Thanks everybody for your help with this!


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .