# How to SetControlRotation using LerpRotator in C++?

**URL:** <https://forums.unrealengine.com/t/how-to-setcontrolrotation-using-lerprotator-in-c/547974>\
**Category:** C++\
**Tags:** UE4-20, unreal-engine, UE4, CPP, question\
**Created:** [May 3, 2022, 7:22pm UTC](https://forums.unrealengine.com/t/how-to-setcontrolrotation-using-lerprotator-in-c/547974 "2022-05-03T19:22:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [May 3, 2022, 7:22pm UTC](https://forums.unrealengine.com/t/how-to-setcontrolrotation-using-lerprotator-in-c/547974/1 "2022-05-03T19:22:39Z")

</div>

An Example in Blueprint.

 ![image_2022-05-04_002011675](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/2/7/627bb42847af57fc750b39afb9cecaa9494e6ae8.png)

A Simple lerp looks like this:  
`FRotator NewRotation = FMath::Lerp(AltReleasedRotation, AltPressedRotation, Percentage, true); //Lerp`

But how to do a Lerp Rotator?

---

<div class="post-metadata">

**Author:** ![Tuerer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tuerer/32/1008648_2.png) [@Tuerer](https://forums.unrealengine.com/u/Tuerer)\
**Post date:** [May 3, 2022, 7:31pm UTC](https://forums.unrealengine.com/t/how-to-setcontrolrotation-using-lerprotator-in-c/547974/2 "2022-05-03T19:31:03Z")

</div>

If I remember it right, if you lerp between FQuats, it will automatically do shortest path.

FQuat NewRotation = FMath::Lerp(FQuat(AltReleasedRotation), FQuat(AltPressedRotation), Percentage);

You can use FQuat in SetActorRotation() etc. instead of FRotator.

---

<div class="post-metadata">

**Author:** ![Tuerer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tuerer/32/1008648_2.png) [@Tuerer](https://forums.unrealengine.com/u/Tuerer)\
**Post date:** [May 3, 2022, 7:37pm UTC](https://forums.unrealengine.com/t/how-to-setcontrolrotation-using-lerprotator-in-c/547974/3 "2022-05-03T19:37:48Z")

</div>

BTW, if you hover over a node, in most cases you can see where the underlying function is. In this case its KismetMathLibrary. You can open KismetMathLibrary.h and find this function Lerp (Rotator), see it’s RLerp(); Go to KismetMathLibrary.cpp, find RLerp(), and see what is does.

With most nodes, you can see how it works in the code, and write your code respectively.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [May 3, 2022, 7:42pm UTC](https://forums.unrealengine.com/t/how-to-setcontrolrotation-using-lerprotator-in-c/547974/4 "2022-05-03T19:42:41Z")

</div>

Thank You very much for helping and replying with a detailed reply.  
But I can’t set **FQuat** in **SetControlRotation**.

 ![image_2022-05-04_004633158](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/0/5/e05993c575904b79bce8a906c973d10a76f52936.png)

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [May 3, 2022, 7:57pm UTC](https://forums.unrealengine.com/t/how-to-setcontrolrotation-using-lerprotator-in-c/547974/5 "2022-05-03T19:57:58Z")

</div>

I am now trying KismetMathLibrary

`FRotator NewRotation = UKismetMathLibrary::RLerp(AltPressedRotation, AltReleasedRotation, Percentage, true);`

but not sure why I am using a blueprint library if I am developing in C++ 😃

---

<div class="post-metadata">

**Author:** ![Tuerer](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/tuerer/32/1008648_2.png) [@Tuerer](https://forums.unrealengine.com/u/Tuerer)\
**Post date:** [May 4, 2022, 9:34am UTC](https://forums.unrealengine.com/t/how-to-setcontrolrotation-using-lerprotator-in-c/547974/6 "2022-05-04T09:34:59Z")

</div>

I didn’t suggest using Kismet library, I said you can see how it’s all done in there. Kismet libraries still use default engine stuff that you can use in c++.  
As for control rotation, maybe there’s no converter from FQuat to FRotator, like in actors. You can always convert it manually. After all, that’s exactly what KismetMathLibrary does:

```auto
FRotator UKismetMathLibrary::RLerp(FRotator A, FRotator B, float Alpha, bool bShortestPath)
{
    // if shortest path, we use Quaternion to interpolate instead of using FRotator
    if (bShortestPath)
    {
        FQuat AQuat(A);
        FQuat BQuat(B);
        FQuat Result = FQuat::Slerp(AQuat, BQuat, Alpha);
        return Result.Rotator();
    }
    const FRotator DeltaAngle = B - A;
    return A + Alpha*DeltaAngle;
}

```

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [May 4, 2022, 11:51am UTC](https://forums.unrealengine.com/t/how-to-setcontrolrotation-using-lerprotator-in-c/547974/7 "2022-05-04T11:51:00Z")

</div>

Yes, Thank You very much Sir for helping me in my study progress, You just solved my problem )

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [May 4, 2022, 12:01pm UTC](https://forums.unrealengine.com/t/how-to-setcontrolrotation-using-lerprotator-in-c/547974/8 "2022-05-04T12:01:24Z")

</div>

```auto
FRotator NewRotation (EForceInit::ForceInit);
NewRotation = FRotator(FQuat::Slerp(FQuat(AltReleasedRotation), FQuat(AltPressedRotation), Percentage));

```

This works for me, Thank You very very much for helping, I really appreciate it :smiley 🙂
