Game Development Reference
This is an effect known as Xeno's paradox . It goes something like this. Let's say you have a slice of
cake, which you cut in half. You cut one of those slices in half once more. Then do the same to the
third slice. The pieces of cake keep getting thinner and thinner. How many times can you slice them
until there's nothing left to slice? Xeno's paradox is that you never reach an end—the pieces of cake
just become infinitely thin, and you can go on slicing them forever. Crazy as it sounds, the math actu-
ally backs this up, and even more crazily, you have to deal with it in AS3.0!
This means that when you apply friction, [rt and [ru never reach zero. The object will never stop
completely. What you need to do then is force a value of zero when [rt and [ru fall below a certain
threshold. This is what this next bit of new code does:
If [rt and [ru fall below an absolute value of ,*-, it forces them a value of ,, thus halting Xeno in his
tracks. ,*- is low enough that it won't have any observable effect on the motion of the object and the
object appears to stop very naturally, even at low friction values such as ,*55. Without this code, your
objects will creep slightly up and to the left on the stage, and never actually stop.
As a quick refresher, I]pd*]^o forces the value in its argument to be positive (“abso-
lute”). It simplifies the code because you don't have to check for negative values.
One final small change to the code is that kjGauQl now no longer sets [rt and [ru to zero. That job is
left for the friction calculation to do. All kjGauQl needs to do is stop the object's acceleration:
And that's it for friction!