Download

Is there a way to put a FVector2D value into a FRotator?

I’m trying to get my character to rotate based on where the mouse cursor is, and I’ve tried using the function DeprojectMousePositionToWorld, but for some reason with that function, the character doesn’t do a full 360, instead, the character stops following the cursor around the 90-degree mark.

So, I thought instead I can use the function GetMousePosition and put the x and y coordinate in an FVector2D, now I just want to know if it is possible to put an FVector2D into a FRotator as the Yaw, or if there are any other alternatives.


UKismetMathLibrary::FindLookAtRotation(characterpoint, targetpoint).Yaw

characterpoint is location of actor

targetpoint is hit position under cursor


    // Trace to see what is under the mouse cursor
    FHitResult Hit;
    GetHitResultUnderCursor(ECC_Visibility, false, Hit);

FVector targetpoint = Hit.ImpactPoint;
FVector characterpoint = GetPawn()->GetActorLocation();

call those 2 from playercontroller
FindLookAtRotation returns FRotator, so u can get any part of this struct that u need.

btw heres my thread with near question