#How to set WorldPosition in new TransformSystem

1 messages · Page 1 of 1 (latest)

civic helm
#

i just updated to newest entities version. The transformAspect is be removed. is there new solution to set worldPosision ?

little hornet
#

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

civic helm
#

oh seem like there is ton on step to do that in newSystem =))

late glen
#

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?

little hornet
#

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

late glen
#

But I have to get the full matrix (which probably involves matrix multiplications for the rotation?), even if I really just want the position?

little hornet
#

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 😄

late glen
#

Yeah, was just asking myself if there is a cheaper way of just getting the position which is already implemented

#

But probably the parent entity lookup is more expensive than the resulting full matrix computation anyways

#

Thank you!