Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rubengrim/bevy_xpbd_interp
A simple library for interpolation of bevy_xpbd rigidbodies
https://github.com/rubengrim/bevy_xpbd_interp
bevy game-development physics
Last synced: 2 months ago
JSON representation
A simple library for interpolation of bevy_xpbd rigidbodies
- Host: GitHub
- URL: https://github.com/rubengrim/bevy_xpbd_interp
- Owner: rubengrim
- Created: 2023-10-02T17:03:50.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-13T16:53:49.000Z (8 months ago)
- Last Synced: 2024-04-14T06:59:26.395Z (8 months ago)
- Topics: bevy, game-development, physics
- Language: Rust
- Homepage:
- Size: 23.4 KB
- Stars: 14
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
**Bevy XPBD Interp** is a simple library for interpolation of [bevy_xpbd](https://github.com/Jondolf/bevy_xpbd/) rigidbodies. It operates by interpolating between the position/rotation of the current and previous physics states based on how much time has accumulated since the last physics update. The interpolated value is stored in the `Transform` of some separate entity that may hold meshes/cameras etc. Physics objects essentially need to be split up into one entity being affected by physics, and one entity being rendered.
In a lot of cases interpolation makes a noticeable difference at normal/higher physics update frequencies, eg. 60hz, but you'll see perfectly smooth movement even at 1hz.
> Note: `bevy_xpbd` is split into a 2d and a 3d crate. This library does the same and is split up into `bevy_xpbd_2d_interp` and `bevy_xpbd_3d_interp`.
>### Usage
Add `bevy_xpbd` and `bevy_xpbd_interp` as dependencies:
```toml
[dependencies]
bevy_xpbd_2d = "0.4"
bevy_xpbd_2d_interp = "0.1.2"
# or
[dependencies]
bevy_xpbd_3d = "0.4"
bevy_xpbd_3d_interp = "0.1.2"
```Then add `XPBDInterpolationPlugin` to your app:
```rust
app.add_plugins(XPBDInterpolationPlugin);
```
Now you can add the `InterpolatedPosition` and/or `InterpolatedRotation` components to any entity with a `Transform`:
```rust
// The entity being affected by bevy_xpbd
let physics_entity = commands
.spawn((
RigidBody::Kinematic,
Position::default(),
Rotation::default(),
))
.id();// Rendered box that uses the interpolated position/rotation
// NOTE: The interpolated entity needs to have a `GlobalTransform` to work properly. Here it's included in the `PbrBundle`.
commands.spawn((
PbrBundle {
mesh: mesh_assets.add(Mesh::from(shape::Box::new(1.0, 1.0, 1.0))),
transform: Transform::default(),
..default()
},
InterpolatedPosition::from_source(physics_entity),
InterpolatedRotation::from_source(physics_entity),
));
```See `'crates/bevy_xpbd_2d_interp/examples/box_2d.rs'` and `'crates/bevy_xpbd_3d_interp/examples/box_3d.rs'` for full examples. Run them with `cargo run --example box_2d/box_3d`.
### Supported versions
| Bevy | Bevy XPBD | Bevy XPBD Interp |
| ---- | --------- | ---------------- |
| 0.13 | 0.4 | 0.1.2 |
| 0.12 | 0.3.2 | 0.1.1 |
| 0.12 | 0.3.1 | 0.1.0 |