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
feat: apply ground friction on predictive velocity correction too #7
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think changing the margin from half a grid cell to one-and-a-half is a good idea.
@@ -125,25 +126,29 @@ fn update_single_cell( | |||
|
|||
if apply_friction { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a better name
if apply_friction { | |
if apply_friction_and_cancel_penetration { |
let tangent_vel = cell_velocity - normal_vel * normal.into_inner(); | ||
let tangent_vel_norm = tangent_vel.norm(); | ||
|
||
let new_normal_vel = normal_vel.max(-dist_with_margin / dt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if we zero the normal velocity out completely, particles can still approach the boundary as their non-zero-kernel space goes further. We may want to extend the margin s.t. we cover the whole range of an approaching particle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This amounts to changing the line above to let dist_with_margin = (dist - cell_width * 1.5).max(0.0);
.
This also restores the previous behavior in the fluid example btw.
Before this change, ground friction was only applied on grid cells below the ground. Now, just like grid cells below the ground induce a friction impulse proportional to the normal velocity, the grid cells above the ground now apply friction proportional to the removed normal velocity due to the predictive contact.