Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

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:
    190
    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:
    190
    andreiagmu likes this.