Skip to content

Instantly share code, notes, and snippets.

@yornaath
Last active August 9, 2023 12:02
Show Gist options
  • Save yornaath/9489722b2b4b6c978b086f8fcf3bdbe5 to your computer and use it in GitHub Desktop.
Save yornaath/9489722b2b4b6c978b086f8fcf3bdbe5 to your computer and use it in GitHub Desktop.
Bevy: constant speed player navigation
fn player_navigation(
time: Res<Time>,
mut player_query: Query<
(
&mut KinematicCharacterController,
&mut Destination,
&mut Transform,
),
With<Player>,
>,
) {
let (mut player_controller, player_destination, player_transform) =
player_query.get_single_mut().unwrap();
let Some(destination) = player_destination.0 else {
return;
};
let direction = (destination) - (player_transform.translation);
let moving = 0.7 * direction.normalize() * time.delta_seconds();
player_controller.translation = Some(moving);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment