bevyengine / bevyengine/bevy

Need to take scale factor into account when transforming Node to world position

Open
#17,312 0 comments 1 reaction 0 assignees View on GitHub
A-UI C-Bug D-Straightforward S-Ready-For-Implementation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version

0.15, latest main

## What went wrong

1. Convert UI node position to world position using camera.viewport_to_world_2d()
2. Set an object in the world to that position, everything seems OK:

![Image](https://github.com/user-attachments/assets/f3069fa1-be97-4ee1-855e-47d01190b393)

3. Someone else runs the app with a scale factor other than 1.0 and sees this:

![Image](https://github.com/user-attachments/assets/3c787b54-0ab6-4152-b173-95bec6af35e5)

## Additional information

Here is the system in question:
```rust
fn move_square_to_node(
mut box_query: Single<&mut Transform, With>,
text_query: Single<&GlobalTransform, With>,
camera_query: Single<(&Camera, &GlobalTransform), With>,
window: Single<&Window>,
) {
let (camera, camera_transform) = *camera_query;

let Ok(point) = camera.viewport_to_world_2d(
camera_transform,
text_query.translation().xy(), // need to divide by window.scale_factor() here
) else {
return;
};

box_query.translation = point.extend(0.0);
}
```
Full MRE here: https://gist.github.com/GitGhillie/44e02ab79f7e054ba939281b738fa10f

Example usecase: Player picks up a coin in the world, and to show this you create an animation where the coin moves from its position in the world to the coin icon in the UI. You want to keep it in the world as long as possible so you can apply effects etc while it is going to the UI position.

If I missed a better approach please let me know!

Contributor guide

Open the contributing guide

Research direction

Start with the linked MRE and the camera.viewport_to_world_2d() call in the reported system. Compare the UI node's GlobalTransform coordinates with Window::scale_factor() and the camera conversion behavior. Done means the world position remains aligned with the UI node when the application scale factor is not 1.0.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.