From bebe7c405da5e7aec3db0915e367b4ff04a49b1c Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Mon, 9 Jun 2025 13:05:58 -0700 Subject: [PATCH] Make camera controller not trigger change detection every frame (#19547) Split off from https://github.com/bevyengine/bevy/pull/19058 --- examples/helpers/camera_controller.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/helpers/camera_controller.rs b/examples/helpers/camera_controller.rs index 07f0f31b11..a60aa69a5e 100644 --- a/examples/helpers/camera_controller.rs +++ b/examples/helpers/camera_controller.rs @@ -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 {