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)
#Grabbing two Transforms
15 messages · Page 1 of 1 (latest)
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
Why does the old solution not work for this?
it does work, i don't like it
like, iterate a Query<(Entity, Target)> and use get_many_mut on a Query<&mut Transform>
How/when do you decide the target for each entity?
why don't you like it?
- potential errors with system ordering, 2) one more property that only exists for this purpose
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
thanks, that actually does the trick, i dunno how i overlooked that
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
my Turn component (indicates that an entity can turn at all) has a Target property, which could be None, Static or Dynamic. so to make something turn towards something else i change this Target property
you don't need to end a system just to drop a borrow, you can copy the immutable Transform entirely if you need to, then borrow the mutable one