I want to Rotate my Obj, but it does not work

I want to program an animator and I wrote following code for that, the Location is working but the Rotation isnt, does someone know why? Here my code

void AU_MainController::MoveToLocation(FVector TargetVector, FRotator TargetRotation)
{

FVector CurrentPosition = GetActorLocation();
FRotator CurrentRotation = GetActorRotation();


FVector NewPosition = FMath::VInterpTo(CurrentPosition, TargetVector, GetWorld()->DeltaTimeSeconds, 5.f);
FRotator NewRotation = FMath::RInterpTo(CurrentRotation, TargetRotation, GetWorld()->DeltaTimeSeconds, 5.f);

SetActorLocationAndRotation(NewPosition, NewRotation);

if (CurrentPosition.Equals(TargetVector, 1.5f))
{
	bIsMovingToPosition = false;
}
else
{
	bIsMovingToPosition = true;
}

}

My initial guess is that the FRotator is in some weird small units (0 to 1 for instance) and the interpolation speed of 5.0f is too much for it. Can you try inputting something much smaller like .1f and tell what happens.

Other than that this snippet seem legit. Maybe you call it with the same value?.. but I’m guessing either way.

Hi!

With object rotation it usually comes down to changing the translation method, like from Relative to World Transform in the Details panel. But in this case with object oriented programming and relying more on C++ than Blueprints, since CurrentPosition.Equals(TargetVector, 1.5f) is used to check proximity for any stopped movement, the script may need to factor in whether the rotational proximity is being checked. Without this, the rotation might continue to interpolate indefinitely. Try adding a similar condition for rotation, like:

  cpp
 if (CurrentPosition.Equals(TargetVector, 1.5f) && CurrentRotation.Equals(TargetRotation, 1.5f))
 {
     bIsMovingToPosition = false;
 }
 
 This ensures the movement stops only when both location and rotation are close enough.

Check if GetWorld()->DeltaTimeSeconds is not a very low value or zero otherwise the interpolation might not progress. You can debug by logging its value. Additionally, make sure SetActorLocationAndRotation accepts and applies the rotation correctly.

Also double-check whether GetActorRotation retrieves the correct rotation.

Can also try:
Logging the NewRotation value every frame to see if it changes.

Verifying that TargetRotation is being called/passed correctly to the function.

Check the Actor Mobility Settings to see if the actor is set to movable. Make sure it isn’t static.

You’re using FMath::RInterpTo, which interpolates smoothly but could fail if CurrentRotation and TargetRotation are mathematically opposite such as 180° apart. In this case, the shortest path between them might not be calculated correctly. You could try normalizing the rotation using:

       cpp
 TargetRotation = TargetRotation.GetNormalized();
 ```

If your project involves multiplayer components, rotation updates might not replicate.

Instead of only using RInterpTo, try a custom interpolation algorithm to ensure smooth rotation transitions, like:
cpp
FQuat CurrentQuat = CurrentRotation.Quaternion();
FQuat TargetQuat = TargetRotation.Quaternion();
FQuat NewQuat = FQuat::Slerp(CurrentQuat, TargetQuat, GetWorld()->DeltaTimeSeconds * 5.f);
FRotator NewRotation = NewQuat.Rotator();

If the rotation is functioning as intended, there may just be blockage or a lack of visual results. Try using debug lines or arrows to visualize the actor’s current and target rotations and enable navigation and debug visualization in the editor and Show tab.
cpp
DrawDebugLine(GetWorld(), CurrentPosition, CurrentPosition + CurrentRotation.Vector() * 100.f, FColor::Red, false, 0.f, 0, 2.f);
DrawDebugLine(GetWorld(), TargetVector, TargetVector + TargetRotation.Vector() * 100.f, FColor::Blue, false, 0.f, 0, 2.f);

Remove or change the collision in the Details for the object by adjusting the actor overlap settings, removing the collision entirely just to see if that unlocks the rotation and adjust the collision bounds and settings by opening the physics asset or static mesh and editing it within the modeling tab to set collision to Complex as Simple and adjust the bounding box area as needed. Could also try:
cpp
GetRootComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);

Let me know if you need more help and post screenshots if you can