#Grabbing two Transforms

15 messages · Page 1 of 1 (latest)

timber salmon
#

i have a problem that i've been struggling with numerous times, and the only solution that kinda works i don't like
i'm making a system for a unit to turn towards either a static position or another unit. if it's another unit, i have to be grabbing both Transforms, one mutably (so i can actually turn), the other immutably (so i know where to turn to). this breaks one of the core Rust principles, but i don't see a way to specify that my unit will never going to be turning towards itself (as in, i won't be taking the same Transform component both mutably and immutably)
the only solution that kinda works is splitting this system into two: one for checking the target Transform and storing the required rotation, the other is for applying the rotation to our unit's Transform. i need to use Quat's lerp/slerp now and that means this kind of separation is very difficult (because with lerp i'm not storing any angle deltas, just rotating immediately)

#

i can't be using marker components for With/Without purposes because source unit and target unit could easily switch roles. or target unit could be turning towards another target unit.

#

i've just doublechecked, and lerp/slerp don't actually change Quat mutably, they return a new Quat. that does help with things, but the initial issue is still present

vague goblet
#

Why does the old solution not work for this?

timber salmon
#

it does work, i don't like it

lost crescent
#

like, iterate a Query<(Entity, Target)> and use get_many_mut on a Query<&mut Transform>

paper crest
vague goblet
timber salmon
vague goblet
#

not sure what you mean. I thought we were talking about the solution of getting the target's transform first, taking what you need, then getting the transform that you need to mutate and mutating it the way you need to

timber salmon
timber salmon
# vague goblet not sure what you mean. I thought we were talking about the solution of getting ...

in my original solution that required two separate systems that were doing essentialy a single action: updating a rotation. having two systems that are so tighly coupled isn't amazing, and i had to have one additional property in a component that stored the intermediate rotation: something that only existed just because i wasn't able to update the rotation within one system. but now i can so it's all good

timber salmon
vague goblet