Skip to main content
7 of 7
added 433 characters in body
OC_RaizW
  • 1.5k
  • 8
  • 27
  • 49

Unity / Rotate a point around an arbitrary axis and anchor

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(float angle ,Vector3 axis, Vector3 anchor)
{
Vector3 oldPosition = gameobject.transform.position;
gameobject.transform.RotateAround(gameobject.GetComponent<HingeJoint>().anchor, gameobject.GetComponent<HingeJoint>().axis, angle);


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

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?

EDIT:

I believe tranform.RotateAround() takes the position and rotation from the transform parameters and calculates the solution and changes the current position and rotation of the gameobject.

So the solution should take 5 parameters:

  1. current position of the unrotated Object
  2. current rotation of the unrotated Object
  3. the point the Object should be able to pass
  4. the rotation axis
  5. the angle

and return 2 parameters:

  1. the rotated objects new rotation
  2. the rotated objects new position
OC_RaizW
  • 1.5k
  • 8
  • 27
  • 49