Rotate a vector around a certain point.

I have already tried transferring my point into a transform, using t.RotateAround, and converting it back into a Vector, but in return, it is giving me a weird error. Instead of trying to fix it, I want to use a better method of doing this. So what would I have to do to rotate my Vector3 around a specific point?

If you want to rotate a vector, multiply it by a Quaternion. Supposing that you want to rotate a vector 60 degrees about the world X axis, for instance:

var myVector: Vector3 = Quaternion.Euler(60, 0, 0) * Vector3.forward;

myVector becomes the vector (0,0,1) rotated 60 degrees about X.

But be aware that a vector indicates a direction in space - it’s not tied to any specific position, thus rotating a vector around a point doesn’t make any sense. If you actually want to rotate a point around a pivot instead, get its direction relative to the pivot and rotate it, then add the rotated direction to the pivot:

function RotatePointAroundPivot(point: Vector3, pivot: Vector3, angles: Vector3): Vector3 {
  var dir: Vector3 = point - pivot; // get point direction relative to pivot
  dir = Quaternion.Euler(angles) * dir; // rotate it
  point = dir + pivot; // calculate rotated point
  return point; // return it
}

If you need to use the RotateAroundPivotPoint function very often this could improve your performance:

public Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles) {
   return Quaternion.Euler(angles) * (point - pivot) + pivot;
 }

It might work better because there are not so many variables in the code which have to be managed.

Thank you all for the above answers. Helped me a lot. but took some time to wrap my mind around this to fit this solution to what I needed to do. I wanted to have a transform move to a new point and rotate it to match this new point’s rotation. But the original transform has a pivot that it needs to rotate around that is not at the center. Posting this here so anyone else that might want to do the same can benefit without having to spend too much time figuring it out.

public class RotTester : MonoBehaviour
{
    [SerializeField] Transform _pivotPosition;//parented to this transform
    [SerializeField] Transform _finalPosition;//I want to move this transform to here

    // Use this for initialization
    void Start()
    {
        //I want to move this object to the target Position
        //First move to target
        transform.position = _finalPosition.position; 
        //set the final position after rotating around the pivot and offset the pivot local position
        transform.position = RotatePointAroundPivot(_finalPosition.position, _pivotPosition.position, _finalPosition.rotation)- _pivotPosition.localPosition;
        //finally set the rotation to target rotation
        transform.rotation = _finalPosition.rotation; 
    }


    public Vector3 RotatePointAroundPivot(Vector3 _finalPosition, Vector3 _pivotPosition, Quaternion _finalRotation)
    {
        return _pivotPosition +(_finalRotation * (_finalPosition - _pivotPosition)); // returns new position of the point;
    }
}