sharpPhysics icon indicating copy to clipboard operation
sharpPhysics copied to clipboard

Broken friction

Open 7Bpencil opened this issue 5 years ago • 2 comments

you define friction as: obj.Velocity -= Friction * dt;

this is the same as: ob.Velocity.X -= Friction * dt; ob.Velocity.Y -= Friction * dt;

So it means if vector component is negative (or zero), it's absolute value increases. It's clearly visible when objects with zero velocity slowly move to the bottom left corner (or top left - depends on coordinate system).

7Bpencil avatar Aug 13 '20 11:08 7Bpencil

I used this

var friction = Friction * dt; PhysMath.RoundToZero(ref velocity, tolerance); velocity.X += velocity.X == 0 ? 0 : velocity.X > 0 ? -friction : friction; velocity.Y += velocity.Y == 0 ? 0 : velocity.Y > 0 ? -friction : friction;

7Bpencil avatar Aug 13 '20 11:08 7Bpencil

Or this: velocity -= Vector2.Normalize(velocity) * friction;

7Bpencil avatar Aug 13 '20 12:08 7Bpencil

Fixed in latest commit

dankelley2 avatar Feb 16 '25 20:02 dankelley2