Make camera controller not trigger change detection every frame (#19547)

Split off from https://github.com/bevyengine/bevy/pull/19058
This commit is contained in:
JMS55 2025-06-09 13:05:58 -07:00 committed by GitHub
parent 476e644a7d
commit bebe7c405d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -198,7 +198,7 @@ fn run_camera_controller(
}
let cursor_grab = *mouse_cursor_grab || *toggle_cursor_grab;
// Apply movement update
// Update velocity
if axis_input != Vec3::ZERO {
let max_speed = if key_input.pressed(controller.key_run) {
controller.run_speed
@ -213,11 +213,15 @@ fn run_camera_controller(
controller.velocity = Vec3::ZERO;
}
}
let forward = *transform.forward();
let right = *transform.right();
transform.translation += controller.velocity.x * dt * right
+ controller.velocity.y * dt * Vec3::Y
+ controller.velocity.z * dt * forward;
// Apply movement update
if controller.velocity != Vec3::ZERO {
let forward = *transform.forward();
let right = *transform.right();
transform.translation += controller.velocity.x * dt * right
+ controller.velocity.y * dt * Vec3::Y
+ controller.velocity.z * dt * forward;
}
// Handle cursor grab
if cursor_grab_change {