Hey guys I’m in a tight bind over here, I am trying to get a smooth rotation of an ACharacter to the mouse cursor, and so far I’ve come up with this:
// Perform a trace and get the mouse hit position vector.
PlayerControllerRef->GetHitResultUnderCursor(TraceChannel, Complex, Hit);
MouseHitPos = Hit.ImpactPoint;
// [DEBUGGING] -- Uncomment this to see trace to cursor
// UKismetSystemLibrary::DrawDebugLine(GetWorld(), GetActorLocation(), MouseHitPos, FColor::Red, 1.f, 5.f);
// Get a vector from the mouse hit point to the actor location
FVector ActorLocationToHitPoint = (MouseHitPos - GetActorLocation());
if (ActorLocationToHitPoint.Size() > 150.f)
{
FRotator UpdateTurningRotation = FMath::RInterpConstantTo(GetActorRotation(), MouseHitPos.Rotation(), DeltaTime, 300.f);
//Orient pawn to the cursor.
SetActorRotation(FRotator(0.f,UKismetMathLibrary::FindLookAtRotation(GetActorLocation(), UpdateTurningRotation.Vector()).Yaw,0.f));
}
// [DEBUGGING] -- Uncomment this to see position of cursor
// UE_LOG(LogTemp, Warning, TEXT("MouseHitPos: %s ActorLocationToHitPoint: %s ActorLocationToHitPoint.Size : %f"), *MouseHitPos.ToString(), *ActorLocationToHitPoint.ToString(), ActorLocationToHitPoint.Size());
The problem is I got the behavior I want, which is a smooth transition from the actor to the direction of the cursor, however I’m unable to move it seems like the calculations at each tick is making my character unable to process movement inputs.
I want to be able to:
Get a trace from the actor to the cursor->RInterp to the rotation of where the the cursor is located.
Currently if I just remove the RInterp, set Actor location snaps the actor towards the actor, and I don’t know if I can get away from that.
Is this just a limited due to the engine’s capability?