Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[Transform] The right way to set global rotation and position

Discussion in 'Data Oriented Technology Stack' started by dzamani, Sep 13, 2018.

  1. dzamani

    dzamani

    Joined:
    Feb 25, 2014
    Posts:
    114
    Hi,

    I have some code that output world positions and rotations. I'm working int a pure ECS context (with parenting transforms), so I'm at the last step and I see that LocalToWorld matrix can't be set because it's overwritten by TransformSystem at each update (also, I was fooled into thinking that Position and Rotation are world which is incorrect when there is a parent and it's very confusing).

    So I have access to :
    - Current localToWorld matrix
    - New localToWorld matrix
    - Parent localToWorld matrix

    My solution is this :

    Code (CSharp):
    1. float4x4 newLocalMatrix = math.mul(math.inverse(parentMatrix), newWorldMatrix);
    This code only works if there is no holes in the hierarchy I'm changing, for example if I have this :
    A -> B - > C - >D
    If I update only A, B and D the math would be wrong because I would not have updated C matrices.

    Is there a plan to handle world positioning ?
    Should we call the Update of TransformSystem manually when we need everything to be recalculated ?

    Thanks!
     
  2. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    404
    As I understand it you want something like Transform.SetParent keeping the current world position.

    Having a 'KeepWorldPosition' in the attach event component would be great.
     
  3. dzamani

    dzamani

    Joined:
    Feb 25, 2014
    Posts:
    114
    Not really, I'm moving Entities based on world positions but these entities have parents / children. For now we have Position and Rotation, which are local if there is a parent, what I want is a SetWorldPosition / Rotation that would be more robust than my solution.
     
  4. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    404
    Why would you want to attach something if the transform should be independent?
     
  5. dzamani

    dzamani

    Joined:
    Feb 25, 2014
    Posts:
    114
    My use case is an IK algorithm working with world positions / rotations, so I'm working on rigs which have transform hierarchies. Some bones could be skipped. So for example I move the wrist of an arm, the hand should follow because it's a child of the wrist.
     
  6. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    404
    Hmm, okay, makes sense.
    I would probably update the hierrachy manually using a list of Bones sorted breadth first, as the problem is limited to specific subhierarchies.
     
  7. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    404
    Or, wait... I think you only have to remove Position/Rotation/Scale from the ones you control for yourself, then LocalToWorld shouldn't be touched by TransformSystem and the children still having these components still move correctly... I think.
     
    Last edited: Sep 13, 2018
  8. dzamani

    dzamani

    Joined:
    Feb 25, 2014
    Posts:
    114
    That's a nice idea but doesn't the TransformSystem needs the parents to have Positions/Rotations components ?
    I will need to think a lot to see if nothing breaks with this idea and I feel like it could give a little performance boost.
    Thanks, that's a good alternative if it works but I still think that a SetWorldPosition would be useful.
     
unityunity