5 Replies Latest reply on May 28, 2008 8:54 AM by voguecreative

# Friction

Hi. I'm trying to implement friction into my code to slow down two balls. Here is my code:

whiteball.vx = 0; /v=velocity in x axis
whiteball.vy = 10; /v=velocity in y axis
whiteball.m = 1; /m=mass

blackball.vx = 0;
blackball.vy = 0;
blackball.m = 1;

_root.onEnterFrame = function (){

whiteball._x += whiteball.vx;
whiteball._y += whiteball.vy;

blackball._x += blackball.vx;
blackball._y += blackball.vy;

I know friction can be used by multiplying by a number less than 0 but im not sure how to impliment it here!

Thanks
• ###### 1. Re: Friction
Not less than 0, less than 1.

Something like - whiteball._x += whiteball.vx * .8;

Then you'll want to add checks to stop it below a certain threshold.

--
Dave -
http://www.blurredistinction.com

• ###### 2. Friction
I'm providing this link on behalf of someone else who makes a regular effort to offer support in the forums, alias clbeech. The animation he provides includes a friction factor that may be of use to you.

http://forums.flashgods.org/rotating-wheel-animation-t104.html
• ###### 3. Re: Friction
Hi guys. Thanks for the replys. I tried to replace my code with

whiteball._x += whiteball.vx * .8; but this didnt seem to make any difference to the speed of the ball. it stayed at a contstant speed.

Any other solutions. Ive looked on other forums and it looks easy when using speed a variable. however im using x and y axis velocities and cant figure it out!
Help!
• ###### 4. Re: Friction
Right... I did say 'something like' :)
What you'll want to do is actually change the velocity by multiplying.

whiteball.vx *= .8;
whiteball._x += whiteball.vx;

--
Dave -
http://www.blurredistinction.com