If you already know the distance and the rotation, you can do something like this:
This function will return the final location for the mesh. Also, you should set the mesh’s rotation to the same rotation used in this function.
If you already know the distance and the rotation, you can do something like this:
This function will return the final location for the mesh. Also, you should set the mesh’s rotation to the same rotation used in this function.
How can I rotate a mesh around an arbitrary point in space?
For example a moon rotating around a planet.
Thanks
Perfect. Thanks!!
Would be possible to create a blueprint function that generates an ellipse movement around an arbitrary point in space. A function that we could input the center point position + the two ellipse focus points positions (that will define the ellipse shape). Is there a way to do it?
Here is my solution to it. It will rotate the object around the given Pivot using the objects own rotation. E.g. A delta rotation around Z will rotate around the objects Z axis. Optionally you can retain the rotation of the object itself.
You can write this as a function, for sure.
UFUNCTION(BlueprintPure)
static void RotateAroundPivot(const FTransform& Original, const FVector PivotLocation, const FRotator DeltaRotation, bool bRetainOrientation, FTransform& New)
{
FTransform PivotTransform = FTransform(Original.GetRotation(), PivotLocation);
FTransform DeltaPivotToOriginal = Original * PivotTransform.Inverse();
New = FTransform(DeltaRotation.GetInverse() * (float)bRetainOrientation, FVector(0,0,0)) * DeltaPivotToOriginal * FTransform(DeltaRotation, FVector(0,0,0)) * PivotTransform;
}
This works regardless of the initial orientation as it doesn’t require the forward vector and has solved my issue of rotating a parent actor around a child actor. I’ve been struggling with this for hours. Thank you so much!