4 releases

0.0.4 Jul 23, 2024
0.0.3 Mar 10, 2024
0.0.2 Dec 3, 2023
0.0.1 Jul 16, 2023

#52 in Game dev

Download history 66/week @ 2024-07-16 159/week @ 2024-07-23 94/week @ 2024-07-30 81/week @ 2024-08-06 67/week @ 2024-08-13 52/week @ 2024-08-20 53/week @ 2024-08-27 98/week @ 2024-09-03 81/week @ 2024-09-10 80/week @ 2024-09-17 105/week @ 2024-09-24 83/week @ 2024-10-01 22/week @ 2024-10-08 64/week @ 2024-10-15 47/week @ 2024-10-22 90/week @ 2024-10-29

225 downloads per month
Used in foxtrot

MIT/Apache

63KB
1.5K SLoC

bevy_dolly

Static Pinned
bevy dolly static bevy dolly pinned
link to crates.io link to docs.rs link to license downloads/link to crates.io stars/github repo github actions tracking bevy release branch

Overview

bevy_dolly is a prototype plugin built for the Bevy game engine. It leverages the powerful dolly crate, developed by h3r2tic, to control camera movement within a Bevy application.

[!WARNING]
Be aware that bevy_dolly's API is still undergoing revisions. Feedback on its ergonomics and developer experience (DX) is highly appreciated.

Dolly and Camera Movement

It's important to know that dolly is all about controlling how the camera moves and not changing the camera itself. This means you can use it for other things, like making a turret and its cannon move around.

Dolly operates in two essential steps:

  1. Creating a Rig: Define a Rig with drivers that the dolly can utilize. These drivers, which can control both translation, rotation, constraints and custom behavior as abstractions. These rigs serve as tools to shape the camera's behavior and provide additional functionality.

  2. Marker Component: Register a marker component on both the Camera and the Rig (rig component tag). This allows you to easily switch the behavior of a camera entity by changing the associated rig component tag. To understand the process better, refer to the examples.

Understanding Drivers

Drivers are mechanisms that influence the behavior of the camera. They can represent constraints or provide additional functionality. To explore the available drivers, refer to the examples.

In your Cargo.toml:

[dependencies]
# Your bevy dependency here ... 
# bevy = "0.14"
bevy_dolly = { version = "0.0.4" }

In your Bevy App:

// The component tag used to parent to a Dolly Rig
#[derive(Component)]
struct MainCamera;

fn main() {
  App::new()
    .add_plugins(DefaultPlugins)
    //..
    .add_systems(Startup, setup)
    .add_systems(Update, Dolly::<MainCamera>::update_active)
    .add_systems(Update, update_input)
    //..
    .run();
}

In the setup system:

// In your setup system
fn setup(
  mut commands: Commands,
) {
  commands.spawn((
    MainCamera, // The rig component tag 
    Rig::builder() // The rig itself
      .with(Position::new(Vec3::ZERO)) // Start position
      // Adds a driver with the method rotate_yaw_pitch
      .with(YawPitch::new().yaw_degrees(45.0).pitch_degrees(-30.0)) 
      // Interpolation when the translation is updated, also known as smoothing
      .with(Smooth::new_position(0.3)) 
      // Interpolation when the rotation is updated (updated via the YawPitch driver)
      .with(Smooth::new_rotation(0.3)) 
      // Moves the camera point out in the Z direction and uses the position as the pivot
      .with(Arm::new(Vec3::Z * 4.0)) 
      .build(),
    Camera3dBundle::default(), // The camera which is related via the rig tag 
  ));
}

And your runtime to update the rig:

fn update_input(
  mut commands: Commands,
  keys: Res<Input<KeyCode>>,
  mut rig_q: Query<&mut Rig>,
) {
  let mut rig = rig_q.single_mut();
  if let Some(yaw_pitch) = rig.try_driver_mut::<YawPitch>() {
      if keys.just_pressed(KeyCode::Z) {
          yaw_pitch.rotate_yaw_pitch(-90.0, 0.0);
      }
  }
}

Helper Plugins

bevy_dolly provides some helper plugins by default, which can be removed if not needed when setting up bevy_dolly as a dependency:

[dependencies]
bevy_dolly = { version = "0.0.4", default-features = false }

To include the drivers back, add features = ["drivers"], to the dependency.

Example Showcase

Explore practical examples in the examples repository.

Running Examples

If you've cloned the project and want to test, execute the following command to run the orbit example:

cargo run --release --example orbit

Compatibility and Support

bevy bevy_dolly
0.14 0.0.4
0.13 0.0.3
0.12 0.0.2
0.11 0.0.1

Alternatives

Explore other Bevy camera controllers that might suit your needs:

Licensing

The project is under a dual license: MIT and Apache 2.0. Feel free to contribute within the bounds of these licenses.

Contributing

Yes this project is still a WIP, so PRs are very welcome.

[!NOTE]
Note that the dolly dependency used is a slightly patched submodule to allow for native bevy transform types. To build the crate locally, run:

git submodule update --init --recursive

Followed by:

cd dolly
git checkout bevy_0.14

Dependencies

~36–74MB
~1.5M SLoC