How to rotate around an arbitrary point?

I found a good way to do this was to do something like this:


    FVector pointLocation = ...
    FVector thingYouRotatePosition = ...
    float amountYouWantToRotate = ... //(0-2pi)

    // make a Quaternion with an upward axis (rotating around the upwards axis)
    FQuat rotation = FQuat(FVector::UpVector, amountYouWantToRotate);

    // get the offset of you the thing you are rotating, from the point
    FVector offset = pointLocation - thingYouRotatePosition;

    // rotate it and add that to the point location
    FVector newRotation = rotation.RotateVector(offset) + pointLocation;

Quaternions are really handy once you learn how to use them. Though most of the explanations I’ve seen seem a little complicated.

How they work is that you give them a vector that tells it what to rotate around, and then you tell it how much to rotate around that ‘axis’. So if you give it a vector that points straight up, it’ll rotate around that like I did above.

1 Like