Bug with linear friction

Topics: Project Management Forum
Aug 24, 2007 at 9:57 PM
The linearFrictionCoefficient property is useful is setting "speed limits" on enemies in a game. The problem is that this causes enemies to prefer traveling diagonally when possible. I'm 99% sure this is because the physics engine processes the X and Y dimensions separately. You can often divide forces into two dimensions like that, but it doesn't work with friction or gravity/magnetism.
Coordinator
Aug 27, 2007 at 2:35 AM
Can you explain further exactly what you are seeing? There is a LinearFrictionCoeficent which works tangent to the contact normal and there is a LinearDragCoeficent which works in the -velocity direction.
Sep 3, 2007 at 1:23 AM

crashlander wrote:
Can you explain further exactly what you are seeing? There is a LinearFrictionCoeficent which works tangent to the contact normal and there is a LinearDragCoeficent which works in the -velocity direction.


Whoops, I meant to say LinearDragCoefficient.

For example, the enemy may calculate that the player is located a long distance away at 30 degrees above the horizontal. It will start moving towards the player until it reaches a maximum X-dimension velocity. Then it's Y-dimension velocity will reach its maximum as the enemy's motion shifts from 30 degrees above the horizontal to 45 degrees.
Sep 3, 2007 at 4:45 AM

ccxvi wrote:

Whoops, I meant to say LinearDragCoefficient.

For example, the enemy may calculate that the player is located a long distance away at 30 degrees above the horizontal. It will start moving towards the player until it reaches a maximum X-dimension velocity. Then it's Y-dimension velocity will reach its maximum as the enemy's motion shifts from 30 degrees above the horizontal to 45 degrees.


What equations do you use to determine how the enemy moves? I think that's be where your problem is, because linear drag is not computed separately for each axis, it's applied in the direction opposite the velocity at the beginning of each timestep (see ApplyDrag() in Body.cs)
Sep 3, 2007 at 8:41 PM
Edited Sep 3, 2007 at 8:43 PM

ccxvi wrote:
I'm 99% sure this is because the physics engine processes the X and Y dimensions separately. You can often divide forces into two dimensions like that, but it doesn't work with friction or gravity/magnetism.


;)
Sep 4, 2007 at 6:22 PM
heheh, so I was thinking the vector2's multiply operator did a dot product, until I noticed that it returns a Vector2 :P so I think if you replace that multiply in ApplyDrag with a dot product you'll have the correct drag formula. Have you tried just changing it to see if it works? Alternatively you can set drag to zero and apply it yourself; I've been doing this in cases where I want to use some less realistic formula that offers tighter control.