dimforge / rapier

2D and 3D physics engines focused on performance.
https://rapier.rs
Apache License 2.0
3.89k stars 242 forks source link

How to run the same time under different refresh rates #483

Closed gygy1993 closed 1 year ago

gygy1993 commented 1 year ago

For example, apply a force to the ball to make it roll. Run it at 60fps and 144fps. 144fps takes a lot less time than 60fps. js version

isaac-mason commented 1 year ago

You might want fixed time steps with interpolation.

This is a good post on the topic: https://gafferongames.com/post/fix_your_timestep/

isaac-mason commented 1 year ago

A good reference for doing this with the js lib could be the @react-three/rapier library: https://github.com/pmndrs/react-three-rapier

See: https://github.com/pmndrs/react-three-rapier/blob/main/packages/react-three-rapier/src/components/Physics.tsx#L395

It's a react library but the approach isn't specific to react.

If you've got more questions specific to the js library though, probably best to create a discussion on the rapier.js GitHub repo, or post some questions in the discord.

gygy1993 commented 1 year ago

A good reference for doing this with the js lib could be the @react-three/rapier library: https://github.com/pmndrs/react-three-rapier

See: https://github.com/pmndrs/react-three-rapier/blob/main/packages/react-three-rapier/src/components/Physics.tsx#L395

It's a react library but the approach isn't specific to react.

If you've got more questions specific to the js library though, probably best to create a discussion on the rapier.js GitHub repo, or post some questions in the discord.

Thanks for your answer, see timestep parameter in world

isaac-mason commented 1 year ago

Yep you can change the timestep each frame (variable time stepping), which is good for many use cases, but has tradeoffs with determinism.