A collection of exponentially-smoothed camera controllers for the Bevy Engine.

Overview

smooth-bevy-cameras

A collection of exponentially-smoothed camera controllers for the Bevy Engine.

Look Transform

All controllers are based on a LookTransform component, which is just an eye point that looks at a target point. By modifying this component, the scene graph Transform will automatically be synchronized.

Any entities with {Transform, LookTransform, Smoother} components will automatically have their Transform smoothed. Smoothing will have no effect on the LookTransform, only the final Transform in the scene graph.

// Enables the system that synchronizes your `Transform`s and `LookTransform`s.
app.add_plugin(LookTransformPlugin);

...

commands
    .spawn_bundle(LookTransformBundle {
        transform: LookTransform { eye, target },
        smoother: Smoother::new(0.9), // Value between 0.0 and 1.0, higher is smoother.
    })
    .insert(PerspectiveCameraBundle::default())

...

fn move_camera_system(mut cameras: Query<&mut LookTransform>) {
    // Later, another system will update the `Transform` and apply smoothing automatically.
    for c in cameras.iter_mut() { c.target += Vec3::new(1.0, 1.0, 1.0); }
}

Look Angles

When implementing a camera controller, it's often useful to work directly with the angles (pitch and yaw) of your look direction. You can do this with the LookAngles type:

let mut angles = LookAngles::from_vector(transform.look_direction());
angles.add_pitch(delta.y);
angles.add_yaw(delta.x);
transform.target = transform.target + transform.radius() * angles.unit_vector();

This is how the built-in controllers implement rotation controls.

Built-In Controllers

These plugins depend on the LookTransformPlugin:

  • FpsCameraPlugin + FpsCameraBundle
    • WASD: Translate on the XZ plane
    • Shift/Space: Translate along the Y axis
    • Mouse: Rotate camera
    • Run example : cargo run --release --example simple_fps
  • OrbitCameraPlugin + OrbitCameraBundle
    • CTRL + mouse drag: Rotate camera
    • Right mouse drag: Pan camera
    • Mouse wheel: Zoom
    • Run example : cargo run --release --example simple_orbit
  • UnrealCameraPlugin + UnrealCameraBundle
    • Left mouse drag: Locomotion
    • Right mouse drag: Rotate camera
    • Left and Right mouse drag: Pan camera
    • Run example : cargo run --release --example simple_unreal
Comments
  • Update to Bevy 0.9

    Update to Bevy 0.9

    Summary

    As of today Bevy is 2 open issues behind the 0.9 milestone. See: https://github.com/bevyengine/bevy/milestone/7 and this crate should support it asap ;)

    Bevy Migration

    • remove deprecated API usage of spawn_bundle() and use spawn() instead
    • remove deprecated API usage of insert_bundle() and use insert() instead

    Maintenance

    • update all crate dependencies
    opened by olegomon 6
  • Movement/Turning speed affected by frame rate

    Movement/Turning speed affected by frame rate

    Movement/Turning (at least using the FPS camera) is heavily dependent on Framerate:

    Pay attention to the FPS counter in the video, and how it correlates with the camera movement and movement speed.

    https://user-images.githubusercontent.com/24855949/191105564-909f7a44-4e10-4d05-9471-1c7893b28c91.mp4

    (video from an example of testing large particle systems, which is why the angle is so weird as to not kill the video compression by looking at 500K particles.)

    opened by laundmo 4
  • Allow pausing interpolation

    Allow pausing interpolation

    Hello! Me again 😅

    This PR is to allow external systems to pause the automatic smoothing and let them control the LookTransform themselves. When they give back control, the smoother shouldn't animate either. Finally, it fixes the "up" vector always set to Vec::Y for all LookTransform. Indeed, the resulting transform from external systems might have another up vector and we shouldn't break continuity when getting the control back.

    Note that this branch builds upon my other PR #11 to update bevy.

    opened by dtaralla 4
  • Panic when zooming all the way in or out with the built in orbit camera controller

    Panic when zooming all the way in or out with the built in orbit camera controller

    I have a simple scene, just the standard Bevy 3d example with the orbit controller added instead of the example's camera. When I zoom all the way in or out, I get a panic with an assertion failed in look_angles.rs:

    CleanShot 2021-12-25 at 17 31 08@2x

    repro scene:

    use bevy::prelude::*;
    use smooth_bevy_cameras::{
        controllers::orbit::{OrbitCameraBundle, OrbitCameraController, OrbitCameraPlugin},
        LookTransformPlugin,
    };
    
    fn main() {
        App::build()
            .add_plugins(DefaultPlugins)
            .add_plugin(LookTransformPlugin)
            .add_plugin(OrbitCameraPlugin::default())
            .add_startup_system(setup.system())
            .run();
    }
    
    fn setup(
        mut commands: Commands,
        mut meshes: ResMut<Assets<Mesh>>,
        mut materials: ResMut<Assets<StandardMaterial>>,
    ) {
        // plane
        commands.spawn_bundle(PbrBundle {
            mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })),
            material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
            ..Default::default()
        });
        // cube
        commands.spawn_bundle(PbrBundle {
            mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
            material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
            transform: Transform::from_xyz(0.0, 0.5, 0.0),
            ..Default::default()
        });
        // light
        commands.spawn_bundle(LightBundle {
            transform: Transform::from_xyz(4.0, 8.0, 4.0),
            ..Default::default()
        });
        // camera
        commands.spawn_bundle(OrbitCameraBundle::new(
            OrbitCameraController::default(),
            PerspectiveCameraBundle::default(),
            Vec3::new(-2.0, 2.5, 5.0),
            Vec3::ZERO,
        ));
    }
    
    opened by sargunv 3
  • Scale wheel event value according to whether they're lines or pixels

    Scale wheel event value according to whether they're lines or pixels

    When using this with bevy in the browser, this previously would give some whacky behavior with the scroll wheel. Previously, this library was just using event.y, which was 53 on my machine. When I ran with a desktop backend, it was using Line, so it was just feeding back 1, so I assume that's what you were testing with because that looked fine.

    opened by rivertam 2
  • Publish on crates.io

    Publish on crates.io

    It seems this hasn't been published on crates.io, which would make trying this a lot easier and less concerning (no worries this repo will update automatically and break my build). Additionally, not publishing means anyone could come in and publish a malicious package with the same name and new users will install it without checking. Please publish a release on crates.io!

    (after going down a rabbit-hole for the last 8 hours, I'm guessing you're also running into this issue, so maybe it will have to wait until after bevy fixes that issue)

    opened by rivertam 2
  • Match UE4 viewport controls for unreal module

    Match UE4 viewport controls for unreal module

    Hello, and first of all: thank you for this plugin, awesome work and very useful/readable.

    I'm using Unreal Editor 4.27 in my day-to-day job, and your mapping for the "Unreal" camera were not exactly mimicking UE4 perspective viewport controls.

    I've modified your unreal module to follow them more closely. I've also tuned the default values of the UnrealCameraController to have better default speeds compared to the Bevy unit. They feel better when navigating in a scene with meshes of diameter 1 but we might want to put them back up if that's not the ordinary case. They just felt better for the simple_unreal.rs example!

    Please don't hesitate to comment/review my code :)

    opened by dtaralla 1
  • Bevy 0.6 update

    Bevy 0.6 update

    I see you're working on updating the master to follow bevy 0.6.0.

    Any chance you can follow bevy tag v0.6.0 or rev 9599af2? ( They are the same commit ). I see you've grabbed on to a slightly newer revision.

    Thanks for a great little plugin!

    opened by mattbradbury 1
  • Remove dependency on bevy_render

    Remove dependency on bevy_render

    This separates the PerspectiveCameraBundle from bevy_render and OrbitCameraBundle UnrealCameraBundle FpsCameraBundle so that this could be used with applications with custom rendering backend.

    opened by Neo-Zhixing 0
  • Reduce bevy dependencies

    Reduce bevy dependencies

    Previously used render feature is a group that contains unneeded stuff, like bevy_ui or bevy_text. Specified features in this PR is the required minimum. You can read more about in in this issue: https://github.com/bevyengine/bevy/issues/4202

    opened by Shatur 0
  • Add missing pub for UnrealCameraController for override input system.

    Add missing pub for UnrealCameraController for override input system.

    This PR makes the UnrealCameraPlugin work identical to the FpsControllerPlugin and OrbitControllerPlugin, without it override_input_system is useless because we cannot actually override the input system without access to ControlEvent !

    opened by exjam 0
  • Does this crate support 2d well?

    Does this crate support 2d well?

    All the examples are using 3D, but I was trying to get it to support 2D as well. It seems i have to manipulate the eye as well to keep the player in the center of the screen, but it makes for a jagged movement

    opened by lecoqjacob 2
  • Floating point error amplification when target and eye are far from the origin

    Floating point error amplification when target and eye are far from the origin

    There is an observable error in the camera angles for the first-person controller (at least), which seems to worsen as you get further from the origin. I assume this is introduced when creating LookAngles or maybe Quat. Anyway, I think it means that we'll need to store the angles separately rather than calculating them from global coordinates every frame.

    This convinces me even more that we want separate coordinates systems for angles and positions, and a different type of smoother for each coordinate system.

    opened by bonsairobo 0
  • Maintain distance while orbiting fast

    Maintain distance while orbiting fast

    The orbit control example seems to bring the camera closer to the look-at point when rotating fast - presumably because it's taking the shortest path in 3D space. Would it be possible to maintain the distance from the centre when rotating?

    opened by mozzius 6
  • Make controllers optional

    Make controllers optional

    Games usually make their own camera controllers. So I would suggest to put controllers under a feature which is enabled by default. If you like the idea - I can send a PR for it.

    opened by Shatur 1
Owner
Duncan
Duncan
A example bevy application using bevy-kajiya for its renderer

☀️ bevy-kajiya playground A example bevy application using bevy-kajiya for its renderer NOTE: only tested on Windows. For more context, check out the

Sebastian Hamel 20 Dec 5, 2022
Payments Engine is a simple toy payments engine

Payments Engine is a simple toy payments engine that reads a series of transactions from a CSV, updates client accounts, handles disputes and chargebacks, and then outputs the state of clients accounts as a CSV.

Bogdan Arabadzhi 0 Feb 3, 2022
Collection of "surprising behaviours" in Rust. In the same spirit of wtfpython and wtfjs.

wtfrust Collection of "surprising behaviours" in Rust. In the same spirit of wtfpython and wtfjs. This document avoids common and general problems in

张实唯 3 Oct 29, 2021
A collection of compilers based around compiling a high level language to a Brainfuck dialect.

tf A collection of compilers based around compiling a high level language to a Brainfuck dialect. Built at, and for, the VolHacks V hackathon during O

adam mcdaniel 6 Nov 25, 2021
A collection of serverless apps that show how Fermyon's Serverless AI

A collection of serverless apps that show how Fermyon's Serverless AI (currently in private beta) works. Reference: https://developer.fermyon.com/spin/serverless-ai-tutorial

Fermyon 15 Oct 20, 2023
Bevy plugin to help implement loading states

This is a plugin for the Bevy game engine, to help you implement loading states.

Ida Iyes 70 Jan 7, 2023
ECS-friendly ldtk plugin for bevy, leveraging bevy_ecs_tilemap

bevy_ecs_ldtk An ECS-friendly ldtk plugin for bevy. Uses bevy_ecs_tilemap as a base. Not released yet, still in development. bevy_ecs_tilemap once sup

Trevor Lovell 247 Jan 10, 2023
An ability / resource / cooldown management library for Bevy.

About leafwing-abilities is an opinionated, ready-to-use Bevy library and plugin for handling abilities. It features: cooldown tracking resource manag

null 2 Mar 30, 2022
Easier joystick, mouse and keyboard input handling in Bevy

Easier joystick, mouse and keyboard input handling in Bevy

Pedro Henrique 31 Dec 20, 2022
Here are a few cargo-generate templates for use when creating bevy applications

Bevy-template-rs Here are a few cargo-generate templates for use when creating bevy applications. Templates Game This is a template for starting a new

Johnny Tidemand Vestergaard 19 Nov 4, 2022
Composable Alternatives to Bevy's RunCriteria, States, FixedTimestep

Composable Alternatives to Bevy's RunCriteria, States, FixedTimestep This crate offers alternatives to the Run Criteria, States, and FixedTimestep sch

null 221 Jan 2, 2023
Inverse kinematics plugin for Bevy implementing the FABRIK algorithm.

Inverse kinematics plugin for Bevy implementing the FABRIK algorithm.

Georg Friedrich Schuppe 11 Dec 31, 2022
MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine

MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine. Both searching and indexing are highly customizable. Features such as typo-tolerance, filters, and synonyms are provided out-of-the-box. For more information about features go to our documentation.

MeiliSearch 31.6k Dec 30, 2022
A simple induction and BMC engine.

Mikino is a (relatively) simple induction and BMC engine. Its goal is to serve as a simple yet interesting tool for those interested in formal verification, especially SMT-based induction.

OCamlPro 21 Oct 8, 2022
A scalable differentiable probabilistic Datalog engine, with Rust

Scallop A scalable probabilistic datalog engine with Rust. Usage The Scallop system is best integrated inside of the Rust context. With scallop! { ...

null 74 Oct 24, 2022
Blueboat is an open-source alternative to Cloudflare Workers. The monolithic engine for serverless web apps.

Blueboat Blueboat is an open-source alternative to Cloudflare Workers. Blueboat aims to be a developer-friendly, multi-tenant platform for serverless

Heyang Zhou 1.8k Jan 9, 2023
A prisma query-engine concurrency runner

Smash A prisma query-engine concurrency runner. Smash can be used to run concurrent requests against the prisma query engine. Currently it has workloa

garren smith 2 Jan 26, 2022
This crate converts Rust compatible regex-syntax to Vim's NFA engine compatible regex.

This crate converts Rust compatible regex-syntax to Vim's NFA engine compatible regex.

kaiuri 1 Feb 11, 2022
Toy: Layout-Engine

Toy: Layout-Engine

Oanakiaja 5 Mar 29, 2022