Can't face character to the cursor's location

Hi,

I am trying to make a platformer where the character will rotate toward the cursor’s location.
The codes are like this:

FVector MouseLocation, MouseDirection;
	GetWorld()->GetFirstPlayerController()->DeprojectMousePositionToWorld(MouseLocation, MouseDirection);

	ACharacter* Player = GetWorld()->GetFirstPlayerController()->GetCharacter();
	FRotator PlayerRotation = Player->GetActorRotation();


	FRotator LookRotation = MouseDirection.Rotation();


	FRotator NewRotation = FRotator(LookRotation.Pitch, 0.f, LookRotation.Roll);

	Player->SetActorRotation(NewRotation );

Then I just call the function in Tick, and it didn’t seem to work.
Both “Use Controller Rotation Pitch” and “Use Controller Rotation Roll” were ticked.

Thanks

If I’m not mistaken, this will return a direction vector form the screen to the world (looking away from the camera). Telling it to look at it would practically be the same as to look from camera to world.

Try this:

	FVector ActorLocation = GetActorLocation();

	FHitResult MouseHitResult;
	Playercontroller->GetHitResultUnderCursor(
		ECollisionChannel::ECC_Visibility,
		false,
		MouseHitResult
	);

	FRotator NewRotation = (MouseHitResult.Location - ActorLocation).Rotation();

	YourActor->SetActorRotation(NewRotation);

Sorry it didn’t work, I have tried using the hitresultundercursor in a similar fashion before. I think since I am doing a side scroller, the cursor is not hitting anything due to my camera set up, unlike in a top-down game. I did find a function called ProjectWorldLocationToScreen, converting 3d vector to 2d, but I can’t get the 2d vector into rotation vector.

I have also tried the following codes but still no luck:

ACharacter* Player = GetWorld()->GetFirstPlayerController()->GetCharacter();
	FVector MouseLocation, MouseDirection;
	GetWorld()->GetFirstPlayerController()->DeprojectMousePositionToWorld(MouseLocation, MouseDirection);
	FVector2D Mouse2D;
	GetWorld()->GetFirstPlayerController()->ProjectWorldLocationToScreen(MouseLocation, Mouse2D);
	FRotator LookRotation = UKismetMathLibrary::FindLookAtRotation(Player->GetCapsuleComponent()->GetComponentLocation(), FVector(Mouse2D.X, Mouse2D.Y, 0.f));
	Player->GetCapsuleComponent()->SetWorldRotation(LookRotation);

And I am using this camera angle:

I just want my character to rotates its body to left/right and up/down base on cursors location on screen.