#How to set WorldPosition in new TransformSystem
1 messages · Page 1 of 1 (latest)
Setting worldposition depends on whether or not you have a parent. In the case where you don't (which honestly can be quite often with correctly set up transform usage flags - since bakers use the information to potentially flatten hiarchries) You can just set the LocalTransform position directly.
In cases where you have a parent. You would need to get the world position first and subtract it from the local position. Something like: localTransform.Position = desiredWorldPosition - worldMatrix.Translation()
Get the world position by using Unity.Transforms.Helpers.ComputeWorldTransformMatrix
oh seem like there is ton on step to do that in newSystem =))
Is getting the worldposition a costly operation?
If I want an entity to follow another entity, I could either have them both with no parent and one system that copies over the localtransforms or just set one as the child of the other (but then often need to calculate the worldtransform of the second entity explicitly). Is one of the approaches prefered?
Well, you could try reading ComputeWorldTransformMatrix. The gist is fairly simple. The more parents you have, the more expensive it is. Profiling is your buddy :3
But I have to get the full matrix (which probably involves matrix multiplications for the rotation?), even if I really just want the position?
Correct, but look at it the other way. The cached value would also have to be computed. Now it isn't being computed unless you decide to. And you know when that calculation happens, and so you know when you can count on it 😄