Download

Player rotation on mouse click

Hello all.
So i have a problem with player rotation. I made a simple click to move script with BP and everything working fine except the rotation as you can see on gif below. Sometimes it rotates after the cursor smoothly and sometimes refuse to even turn to that direction

Imgur: The magic of the Internet (gif 7mb)

The script itself

I also copy/pasted the click to move script from TopDown template and got the same rotation problem. So i’d realy apreciate if you can help me with this or give some tip maybe i’m doing something wrong.

Hi,
I think that the issue you are facing here is that you take the rotation from vector that the mouse hit result generates. This will not give you a value that represents the rotation from your actor to the hit result.

First: Setting the rotation of a pawn or actor is not something that should be done by SetControlRotation I believe. What you want to do is SetActorRotation. Do this by dragging of the player controller and GetControlledActor. From there you can set the controlled actor rotation.

**Second: **Try to experiment with a **FindLookAtRotation **node. What you need to get is your player actor´s location and plug it into the start of FindLookAtRotation. Then you plug in the mouse hit result vector into the target of FindLookAtRotation. This gives you the rotation that your playable actor has to have to look at the mouse location.
To create a smooth rotating movement you can plug your current actor rotation into a **RInterpTo **node as the current value and plug the FindLookAtRotation into the target value. The last setting is to plug delta time of EventTick into delta time of RInterpTo. The output is then connected to SetActorRotation. See screenshot below for visual guide (I have some differences in implementation but they are small).

Wow thanks alot, RInterp worked like magic and everything runs smoothly now. But it runs with **SetControlRotation **and not with SetActorRotation
Final result (a bit messy, i know)

Glad to hear it! :slight_smile:

How to make the player rotate towards the cursor in empty space, where there is nothing under the cursor?

I made your blueprint but it didn’t work for me, the player doesn’t rotate. Do I have to do anything else?

https://forums.unrealengine.com/core/image/png;base64