-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Add bevy_camera_controllers crate and move freecam implementation into it #20215
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
base: main
Are you sure you want to change the base?
Add bevy_camera_controllers crate and move freecam implementation into it #20215
Conversation
Module docs Hook up new crate to bevy_internal Stub for fly_cam camera controller Steal existing free-cam controller
This comment was marked as duplicate.
This comment was marked as duplicate.
i worry a bit about the added friction of having to run some examples with |
@@ -298,6 +298,10 @@ bevy_gizmos = ["bevy_internal/bevy_gizmos", "bevy_color"] | |||
# Provides a collection of developer tools | |||
bevy_dev_tools = ["bevy_internal/bevy_dev_tools"] | |||
|
|||
# Provides a collection of prebuilt camera controllers | |||
bevy_camera_controllers = ["bevy_internal/bevy_camera_controllers"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we sure we want plural crate name?
bevy_camera_controllers::free_cam
bevy_camera_controllers::fly_cam
vs
bevy_camera_controller::free_cam
bevy_camera_controller::fly_cam
@@ -4,13 +4,12 @@ | |||
//! - Insert an initialized `SceneHandle` resource into your App's `AssetServer`. | |||
|
|||
use bevy::{ | |||
gltf::Gltf, input::common_conditions::input_just_pressed, prelude::*, scene::InstanceId, | |||
camera_controllers::free_cam::FreeCamController, gltf::Gltf, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be cool to re-export this from top level crate and probably shorten it to just FreeCam
maybe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we overuse re-exports! Shortening it would be good though.
This comment was marked as duplicate.
This comment was marked as duplicate.
I think it's ok, there is some minor friction but the required-features should prompt people well enough and may add to discoverability of how to add FreeCam for your own project. |
Co-authored-by: atlv <email@atlasdostal.com>
Yeah, the prompt is very helpful. I don't like having to add it, but the alternative is to add it to the default features. Since 99% of games won't want to ship with this in production, the only way to reclaim that binary size / compile speed will be to turn off Bevy's default features and slowly build it back up. |
The generated |
I have some feedback and improvements in mind for this code, but as per the "notes for reviewers", I think it would mostly be out of scope for this initial PR. Should I wait until this PR is merged to follow-up on it, or is there an appropriate way to share the feedback immediately? |
Leave your feedback here for now, and then we can come back to this thread for notes when merged :) |
On line 183 (Github won't let me comment on that line directly because it's outside of the diff), the scroll delta is divided by 16 if the unit is pixels, and not if the unit is lines. This seems odd to me, both because it's undocumented, and because no other use of mouse scrolling I could find in Bevy cares about the scroll units. The PR that added this was #11921, and reading the comments there reveals that the choice of 16 as the divisor was both arbitrary and untested. Someone should actually test pixel scrolling, and either confirm that 16 is fine, or update it to something better (and also document it either way). Alternatively, the special-casing based on the units could just be removed entirely. |
Line 186 (also outside the diff) is where the movement speed is updated based on the mouse scrolling, however the way it is done is flawed. Ideally, the effect of The correct way to do it, that does have this property we want, looks something like this: -controller.walk_speed += scroll * controller.scroll_factor * controller.walk_speed;
+controller.walk_speed *= (controller.scroll_factor + 1.0).powf(scroll); This should also be documented when implemented, and maybe someone who understands the math better than me can explain why/how it works, beyond just that It Does. |
Line 235 (not in diff etc.), the way friction is applied should take the delta time into account. Given that it's implementing an exponential decay, it should be refactored to use |
Lastly, and most subjectively, I think the default sensitivity is way too high. I should not be doing 360s with ~1cm of physical mouse movement (and I say this as someone who tends to turn mouse sensitivity up in most games I play). |
For traceability I'll link the issue on upstreaming If I'm reading the context correctly the outcome of upstreaming that would be as a controller in Nit: The OP says "I don't intend to land this in Bevy 0.18", I assume this should say 0.17? |
FWIW this should be reflective of the default 1.0 sensitivity from Valorant, if it doesn't match for you in that then there was probably something wrong with my math. |
Objective
Moving the camera around is really important to validate that our scenes are rendered correctly.
Bevy engine devs currently do this via a fairly cursed "library example" which includes a basic freecam controller (which is technically distinct from a flycam apparently). This has three problems:
Solution
Create a new
bevy_camera_controllers
crate, and move the existing freecam implementation into it, nearly verbatim.This cleans up some ugly tech debt in how we do this, makes it easier to add a camera controller to other examples, and also gives us a scaffold for future camera controllers.
This PR has been marked
X-Blessed
, as I went over this plan with @cart in a meeting on 2025-06-23, and we both agreed that this was the right first step.Testing
I've tested the examples that rely on this camera controller: they work just like before.
Notes for reviewers
TODO
Future work