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

Adaptive Physics Time Step #989

Merged
merged 9 commits into from
Jun 29, 2024
Merged

Conversation

HunterBarclay
Copy link
Member

Description

Modulate the physics time step to no longer be fixed, and instead slightly adjust it towards the actual DeltaT. During the original Spike of JoltPhysics, we discovered the significant impact that adjusting the physics delta can have. Ideally we'd have a fixed, consistent time step; however, this is proving difficult as we would like to accommodate the varying performance levels.

Warning

This is a bandage. We may want to look into better ways of smoothing out the physics step.
We should also investigate allowing advance options to manual set/configure physics time steps.

Adjustment Method

We initially set a physics step rate of 120FPS. We then calculate the difference between the last used deltaT and the current frames recorded deltaT. This change is capped out to a constant and the targeted deltaT is then adjusted by this capped difference. We then calculate number of sub steps via the inverse of this deltaT. This way we can try to make up for lack of frames per second with more physical calculation.

Important

All of these values are limited with constants that can be found in PhysicsSystem.ts

Downsides

Sub steps can't seem to be calculated to a good value that doesn't flip between two adjacent numbers, at higher frame rates. In addition, this inconsistent deltaT generally decays the fidelity of the simulation.

JIRA Issue

@HunterBarclay HunterBarclay added the physics Relating to either the underlying physics engine or the usage of it label Jun 24, 2024
@HunterBarclay HunterBarclay self-assigned this Jun 24, 2024
@HunterBarclay HunterBarclay requested a review from a team as a code owner June 24, 2024 14:47
@HunterBarclay HunterBarclay requested review from PepperLola and LucaHaverty and removed request for a team June 24, 2024 14:47
Copy link
Collaborator

@LucaHaverty LucaHaverty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worked well on my machine at various frame rates. Nice work!

@HunterBarclay
Copy link
Member Author

@LucaHaverty @PepperLola Fixed prettier and lint validation and fixing. Updated workflow to check them separately.

Copy link
Collaborator

@LucaHaverty LucaHaverty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work at around 60fps, but when it drops to 30 I noticed joints flying apart and robots falling through the ground

image

@LucaHaverty LucaHaverty self-requested a review June 28, 2024 20:59
@HunterBarclay
Copy link
Member Author

@LucaHaverty @PepperLola It looks like the number of substeps is decreasing as the frame rate drops which isn't right. I'll take a look.

@HunterBarclay
Copy link
Member Author

K, I was actually shocked at the fidelity with this last change. I couldn't see any significant joint drift
@LucaHaverty @PepperLola

Copy link
Member

@PepperLola PepperLola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performed a lot better after the substep changes.

@HunterBarclay HunterBarclay merged commit 8fbe56b into dev Jun 29, 2024
11 of 12 checks passed
@HunterBarclay HunterBarclay deleted the barclah/1716/physics-time-step branch June 29, 2024 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
physics Relating to either the underlying physics engine or the usage of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants