kulkalkul / bevy_mod_billboard

Billboard text and texture support for bevy
Apache License 2.0
91 stars 14 forks source link

Rotating camera around y-axis causes unexpected behavior #21

Open bkwhite opened 8 months ago

bkwhite commented 8 months ago

Billboard textures seem to have weird behavior when the camera is rotated on the y-axis. The weirdness happens after a sprite is scaled. (Scaling translation.x when the bullet hits the hitbox)

Initialing camera with Y rotation

let mut camera_transform = Transform::from_translation(Vec3::new(3.3, 1.0, 9.5));
camera_transform.rotate_axis(Vec3::X, deg_to_rad(-45.0));
camera_transform.rotate_axis(Vec3::Y, deg_to_rad(-45.0));

// main camera
commands.spawn((
    Camera3dBundle {
        transform: camera_transform,
        projection: OrthographicProjection {
            far: 100.0,
            near: -100.0,
            // this is how far the camera is away from the focus
            scale: 6.0,
            scaling_mode: ScalingMode::FixedVertical(2.0),
            ..default()
        }.into(),
        ..default()
    },
    MainCamera,
));

Spawning Billboard Sprite

commands
    .spawn(BillboardTextureBundle {
        texture: BillboardTextureHandle(scene_assets.health_bar.clone()),
        mesh: BillboardMeshHandle(meshes.add(Quad::new(value_shape_size * 2.0).into())),
        transform: Transform::from_xyz(0.0, npc_info.info.height / 2., 0.0),
        ..default()
    })
    .insert(HealthBar)
    .insert(NpcIdentification {
        id: npc_info.identification.id.clone(),
    })
    .id();

Weird behavior (video)

https://github.com/kulkalkul/bevy_mod_billboard/assets/1873332/081e2600-b74d-4add-b581-415b62d47c3d

kulkalkul commented 8 months ago

Hey, thanks! I'll check this out tomorrow, see if I can reproduce and figure a fix if possible.

bkwhite commented 8 months ago

Hey, thanks! I'll check this out tomorrow, see if I can reproduce and figure a fix if possible.

awesome! thanks, this crate is really helpful I wanna keep using it!

I can add you to my repo for the rest of my game's code if needed!

kulkalkul commented 8 months ago

👋 I was able to reproduce it, though I'm not sure how I should solve it. So, it seems like the issue is with orthographic projection. I don't know if I can modify the matrix multiplication in a way so it works for both cases or if I should add another pipeline key for orthographic case.

bkwhite commented 8 months ago

Glad it was reproducible, but unfortunate it sounds complicated. Both of these ideas so solve this sound over my head at the moment.

Has orthographic stuff required a different pipeline keep for anything else?

kulkalkul commented 8 months ago

My understanding of graphics programming, especially the maths part of it, is pretty weak. I've only implemented a basic orthographic projection for my own engine and haven't used bevy seriously for more than half a year. So I don't really know if this is the norm or not. I'll probably try the second option as that feels like the easiest at the moment. Though I still need to figure a formula that plays nice with orthographic.