Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GlobalTarget when reading the position of the Gizmo camera #52

Merged
merged 1 commit into from
Apr 12, 2024
Merged

Conversation

AlexAegis
Copy link
Contributor

@AlexAegis AlexAegis commented Apr 11, 2024

Description

Found a problem where, if the Gizmo camera is parented to something, then the gizmo will appear off.

(In my top-down game the camera is parented to a "selfie stick" to make it easier to move without having to worry about its angle towards the ground)

The fix looked easy hence the PR, it should just read the GlobalTransform of the camera instead of the local.

Bug Demo

In another branch I made a very rudimentary change to your example to showcase the bug, I only modified the scene.rs file: https://github.com/AlexAegis/transform-gizmo/blob/non-global-camera-bug-demo/examples/bevy/src/scene.rs

edit: I deleted my fork, here's the changed part of the example for reference:

#[derive(Component)]
struct SelfieStick;

fn move_camera(mut selfie_stick_query: Query<&mut Transform, With<SelfieStick>>) {
    for mut stick_transform in selfie_stick_query.iter_mut() {
        stick_transform.translation.x -= 0.01;
        stick_transform.translation.y += 0.01;
    }
}

fn setup_scene(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    let camera_transform = Transform::from_xyz(5.0, 5.0, 5.0);

    commands
        .spawn((TransformBundle::IDENTITY, SelfieStick))
        .with_children(|parent| {
            parent.spawn((
                Camera3dBundle {
                    transform: camera_transform.looking_at(Vec3::ZERO, Vec3::Y),
                    ..default()
                },
                GizmoCamera,
            ));
        });

@urholaukkarinen urholaukkarinen merged commit 49b3588 into urholaukkarinen:main Apr 12, 2024
1 check passed
@urholaukkarinen
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants