Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Resolved Rotate child direction vector around with parent

Discussion in 'Physics for ECS' started by NT_Ninetails, Sep 29, 2021.

  1. NT_Ninetails

    NT_Ninetails

    Joined:
    Jan 21, 2018
    Posts:
    196
    So I have a child that generates a force in a direction let's say (0,0,-1)[backwards]. If the parent is rotate 90 degrees then to apply that force correct on the child i use this code.

    Code (CSharp):
    1.   public static Vector3 RotateDirectionVector(Vector3 direction, Vector3 rotation)
    2.         {
    3.             direction.Normalize();
    4.             Quaternion rot = Quaternion.Euler(rotation); // Rotate [angle] degrees about the x axis.
    5.             direction = rot * direction;
    6.             return direction;
    7.         }
    However if I have a parent->child->child->child->child then the resulting direction vector of the final child is off a bit off. I know it has to do with the child's parent parent parent affecting the proper rotation however, I'm not sure how to approach this problem.



    Any ideas?
     
  2. NT_Ninetails

    NT_Ninetails

    Joined:
    Jan 21, 2018
    Posts:
    196
    andreiagmu likes this.