1

I am using the Bevy game engine.

The ability to have transforms be propagated to children in Bevy is handy, but when I am performing collision checks in my game, I have been using the object's Translation to compute its location. Now that I have some parent-child hierarchies in my scene, the Translation of each child entity is relative to its parent.

Is there a way to get the position of an entity relative to the world origin as opposed to the entity's parent?

EtTuBrute
  • 502
  • 5
  • 16
  • It's hard to answer your question because it doesn't include a [MRE]. We can't tell what crates (and their versions), types, traits, fields, etc. are present in the code. It would make it easier for us to help you if you try to reproduce your error on the [Rust Playground](https://play.rust-lang.org) if possible, otherwise in a brand new Cargo project, then [edit] your question to include the additional info. There are [Rust-specific MRE tips](//stackoverflow.com/tags/rust/info) you can use to reduce your original code for posting here. Thanks! – Shepmaster Sep 02 '20 at 15:21
  • Removed the rust tag and added the line at the top specifying that this is in the context of the Bevy engine. I will see about adding a code example as well – EtTuBrute Sep 02 '20 at 16:11

1 Answers1

4

The "world" position is stored in the GlobalTransform component. Transforms internally are 4x4 matrices where the translation() function returns the position. You can access it like this:

fn system(global_transform: &GlobalTransform) {
  let position = global_transform.translation(); 
}
silentbat
  • 101
  • 1
  • 3
cart
  • 286
  • 1
  • 3
  • That doesn't work. w_axis gives you the relative translation not the absolute position. – Cpt. Red Oct 05 '20 at 12:39
  • 1
    Indeed! This was prior to a rework of the transform system in Bevy. Now you should use `GlobalTransform::translation()` – cart Oct 06 '20 at 18:30