Skip to content

Commit

Permalink
Normalize the player's direction vector
Browse files Browse the repository at this point in the history
  • Loading branch information
theredfish committed Jun 9, 2024
1 parent fae9754 commit f07b159
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion examples/camera/2d_top_down_camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ fn move_player(
direction.x = 1.;
}

let move_delta = direction * PLAYER_SPEED * time.delta_seconds();
// Progressively update the player's position over time. Normalize the
// direction vector to prevent it from exceeding a magnitude of 1 when
// moving diagonally.
let move_delta = direction.normalize_or_zero() * PLAYER_SPEED * time.delta_seconds();
player.translation += move_delta.extend(0.);
}

0 comments on commit f07b159

Please sign in to comment.