Skip to main content

Unity / Rotate a point around an arbitrary axis

I'm trying to find out the point which is already rotated. To solve this I did a Rotation, save the position, set the previous position and return my position, like this:

Vector3 rotatePointAroundAxis(Vector3 point,float angle ,Vector3 axis, Vector3 anchor)
{
Vector3 oldPosition = gameobject.transform.position;
gameobject.transform.Rotate(gameobject.transform.position, angle,gameobject.GetComponent<HingeJoint>().axis,gameobject.GetComponent<HingeJoint>().anchor);

Vector3 newPosition = gameobject.transform.position;
gameobject.transform.position = oldPosition;
return newPosition;
}

But if I rotate my gameobject like in that code, I am also rotating all the children. So I need to do that transformation myself.

I searched already. And I found very hard solutions. http://inside.mines.edu/fs_home/gmurray/ArbitraryAxisRotation/

  • by the way i dont think I understand this, it seems like too much.

Is there any way to change that function to a "simple" one, so I don't need to rotate things forth and back to get the coordinates?

OC_RaizW
  • 1.5k
  • 8
  • 27
  • 49