#Rendering mesh that stick real time to camera ?

8 messages · Page 1 of 1 (latest)

zenith terrace
#

Hello,

I want to make a simple card UI system (like Hearthstone, Gwent, or Slay The Spire etc.. but no so elaborate just want to display card in bottom and launch a tween animation on hover) . So I made a Box with a 0.1 depth, I first tried to attach it to my camera as children but it doesn't worked as expected so I made a system like this ```fn update_cards_pos(
camera_query: Query<&GlobalTransform, With<MainCamera>>,
mut card_query: Query<&mut Transform, With<Card>>,
) {
if let Ok(global_transform) = camera_query.get_single() {
if let Ok(mut card_transform) = card_query.get_single_mut() {
let transform = global_transform.compute_transform();
let translation =
transform.translation + transform.down() * 0.29 + transform.forward() * 1.0;

        card_transform.translation = translation;
        card_transform.rotation = transform.rotation;
    }
}

}


somehow it "works" it is following and facing my camera but I move the camera there is a little between my camera moves and the card moves. And I feel like this isn't the right way to do it. So my question is does anyone has resources to share that explain how can I achieve this properly ?

Thank you for help
frank forge
#

So there is two questions in this

1. Why can't I see the card when I set it as child of a camera

(usually bevy prints a warning message in the console for that, not sure why you are not getting it)
Try adding the SpatialBundle component to your camera entity.
The cards do not render as children of the camera, because they are child of an entity without the Visibility component, adding SpatialBundle to all parents of your cards fixes it.

2. Is this a valid approach

Having a system that updates transform based on other entitie's transform is perfectly valid. For example, an enemy chasing the player would need such a system.

minor lava
#

The GlobalTransform vs. Transform is likely causing the issue

frank forge
#

3. Why is this not working

You are using the camera's GlobalTransform then, using it to set the cards' Transform. All entitie's GlobalTransform are updated in the propagate_transforms system in CoreSet::PostUpdate.

minor lava
#

ah, you were getting there =)

frank forge
#

So you will always be using the last frame's camera Transform as the source of truth for your card's positions. Which results in delays. What you want to do, is either use the Transform of the camera instead of its GlobalTransform or insert a copy of propagate_transforms to run just before update_cards_pos

zenith terrace
#

I added Visibility components manualy (I use another crate on camera that add Transform and Global transform) on the camera and it did not work either. Thank you for helping, I will try using the Transform camera's component instead. For simplifying things if I thought adding another camera only for the card (since I read some do this technique for HUD) will it be better ?

#

It is indeed much better with Transform