Friction And Visual Basic

I’m making a mini golf game in VB and I’m trying to get the friction to work right. I have different “terrains”, ranging from cement to grass to sand. Each has their own number, called “friction”. The numbers range from 2 to 9.

The ball is controlled by two variables, “movementx” and “movementy”. One controls the left-right movement of the ball, the other, up down. Another variable, “ballmovement”, is the total vector of the aforementionned variables.

frictionspeed = ballmovement * ???
movementx = movementx - frictionspeed * movementx / ballmovement
movementy = movementy - frictionspeed * movementy / ballmovement

“frictionspeed” is supposed to be how much deceleration the ball experiences in total. But I don’t know how to get the value. Whatever I try, it either comes to a screeching halt, or never stops.

Friction between two solid surfaces (such as your ball and the green) is usually approximately independent of speed. Exception: It matters if they’re stopped or moving. Static friction is usually larger than dynamic friction. For the most part, friction only becomes proportional to the speed (or speed squared) when you’re dealing with fluids.

Of course, friction is very difficult to model exactly, so these are only approximations. It should be good enough for your game, though.

I thought that friction, in the absence of other forces, generally resulted in an exponential decay of speed, i.e.,
S(t) = S[sub]0[/sub] * e[sup]-t * K/m[/sup], where t is time, m is the mass of the object, and K is the frictional coefficient.

So, assuming timesteps of equal length, just use the statements

movementx = movementx * falloff
movementy = movementy * falloff

where falloff is some number between 0 and 1. Cement should be closer to 1 than sand, but exactly which values they should be set to will depend upon what units of distance and time you’re planning on using.

I’ll just make it

movementx = movementx - friction * movementx / ballmovement

Thanks Chronos. I thought it would be dependant on the speed, so it was making things complicated.

Punoqllads, I’m sure you formula would work more accurately, but for the sake of simplicity and loading time, I’ll just do this.