Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken friction #5

Closed
7Bpencil opened this issue Aug 13, 2020 · 3 comments
Closed

Broken friction #5

7Bpencil opened this issue Aug 13, 2020 · 3 comments

Comments

@7Bpencil
Copy link

7Bpencil commented Aug 13, 2020

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
Copy link
Author

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
Copy link
Author

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

@dankelley2
Copy link
Owner

Fixed in latest commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants