Rotate Mesh by 360 degrees over a given Time Period

Hey there,
I am trying to rotate a meshs Yaw Value for 360 degrees over a period of 10 minutes (let’s say). Would this be possible with this code snippet I created or do I need to tweak things and if so, what?


float DayDuration = 600.0f;

float YawRotation = 0.0f;

Tick Function:

while(YawRotation < 360.f) {

YawRotation += 360 / SecondsDayDuration * DeltaTime;

FRotator NewRotation = FRotator(0.0f, YawRotation, 0.0f);

FQuat QuatRotation = FQuat(NewRotation);

Cube->AddActorLocalRotation(QuatRotation, false, 0, ETeleportType::None);

else YawRotation = 0.0f;

The DayDuration setting the time you need for one whole rotation.

there is a better function called MoveComponentTo inside UKismetSystemLibrary that does this. and doesn’t even need to be called from tick.

And this function can rotate a Mesh over a period of time that I can set?


with the overtime parameter, u can specify how long it should take to rotate or move the actor.

FLatentActionInfo Latentinfo;

Latentinfo.CallbackTarget = this;

UKismetSystemLibrary::MoveComponentTo(DoorMesh, FVector(StartLocationX, StartLocationY, StartLocationZ), FRotator(StartRotationY, StartRotationZ, StartRotationX), true, true, 1.f, true, EMoveComponentAction::Type::Move, Latentinfo); 

i forgot to mention. u must also include the necessary header file otherwise it won’t work.

#include "Kismet/KismetSystemLibrary.h"

Thanks alot! That sounds promising. However I could not seem to find it in the documentation. Would you mind to explain the parameters of the function to me? StartLocation and StartRotation are pretty obvious but what are those booleans and where to set the time over which my mesh should be rotated? Also, is it always rotated 360 degrees or can I set this number anywhere? I guess doormesh is the mesh you want to rotate? From where do I call this function because you said it doesn’t needed to be called from tick?

Thank you so far!

Pay attention when using MoveComponentTo. To rotate 360º, you will have to called it at least twice. For example: once for 0º->180º and again for 181º->360º. Otherwise, if you call it once for 0º->360º it won’t rotate. For 0º->359º, it will rotate directly from 0º to -1º.

Ok, I will keep that in mind thanks!
But where do I actually pass into the function how many degrees it should rotate? As I see, there are only parameters for starting location/rotation and time but no parameters for amount of rotation or new rotation/location.

There are no “starting location/rotation and time”. *TargetRelativeLocation *and *TargetRelativeRotation *are the final location/rotation of the component. So, if you want to make a 180º rotation in situ in 10 seconds, then,

TargetRelativeLocation = GetWorldLocation();
TargetRelativeRotation = FRotator(0.f, 0.f, 180.f);
FLatentActionInfo LatentEnd;
LatentEnd.CallbackTarget = this;

UKismetSystemLibrary::MoveComponentTo(MyMeshComponent, TargetRelativeLocation, TargetRelativeRotation, false, false, 10.0f, false, EMoveComponentAction::Type::Move, Latentinfo);

Does the component rotates only once or does it rotates forever? If not, since you’re rotating the entire actor, consider using a Rotating Component.

It is rotating forever.
What do you mean by saying I should consider using a rotation component?

Sorry, I am so new to all of this :smiley:

Edit: I looked it up, nevermind. But for me it seems that with the Rotation Component you can’t set the time in which it should rotate bei 360 degree. :confused:

The rotation rate of *URotatingMovementComponent *is directly related with time:

Rotation rate = (0,0,90) => makes a 360º yaw rotation every ~4s
Rotation rate = (0,0,180) => makes a 360º yaw rotation every ~2s
Rotation rate = (0,0,360) => makes a 360º yaw rotation every ~1s

So, for 10 minutes 360º yaw rot: Rotation rate = (0,0,0.6f)

Ok thank you, I will give it a try :slight_smile:
Seems the easiest :slight_smile: