Download

Rotate player smoothly to direction of velocity

Hi! I’m trying to get my player character to smoothly rotate towards the direction of velocity so that forward or backward + left or right are interpreted as forward (1,0,0). In other words if I put an arrow on the capsule, diagonal would be forward on the diagonal relative to the camera. It should work with backward running as well, so the diagonal would rotate inverse as well.

It’s also important that when strafing the player does not rotate towards velocity as it would undo the strafing animation.

I can get the velocity, normalize it and set actor rotation towards the normalized vector with an Rinterp node on the yaw but not getting accurate results. Would really appreciate some help to figure it out.

Thanks in advance!

Not sure if I understood your problem correctly. But have you tried checking Use Controller Desired Rotation on your characters movement component?

Hmm, thank you but: yes I tried that and it actually does not rotate the capsule towards the acceleration. If I put an arrow component on the capsule for debugging, it points forward and not diagonal when moving diagonally with Fwd+Left or Fwd+Right etc. My issue is also to get smooth rotation towards the direction of acceleration or velocity. The second issue is that it needs to be clamped so that moving left or right does not rotate the capsule towards acceleration or velocity as that would mess up my strafe blends in the animgraph.

This and lower the Yaw rotation speed.

No, unfortunately this does not do what I need it to do. If I put an arrow component on the capsule for debugging with Use Controller Desired Rotation or Orient Rotation to Movement checked, it will still point forward, not smoothly turn towards the direction of acceleration. Not sure why it’s like that but I need another solution. I need something that smoothly rotates towards the direction of velocity or acceleration. Here’s a video of the problem. In the video you can first see that forward, backward and strafing is correct but diagonals do not rotate the capsule, which means that diagonal forward is interpeted as a 50/50 value between side and forward, resulting in a strange blend between forward run and side strafe. I need forward diagonals to be “forward on the diagonal” and backward diagonals to be the inverse so that running backwards diagonally keeps the capsule facing forwards but inversely, if that makes any sense (you can also see the issue clearly on the top left corner, that is the direction of velocity normalized to 0-1, blue is forward/backward, red is left/right):

In your case use Orient Rotation to Movement instead. That can also be found on the movement component. You can specify the rotation rate there as well, so it will smoothly rotate.

I wrote the wrong check box. It’s the same issue with Orient Rotation to movement

UPDATE it works when I uncheck *Use Controller Rotation Yaw’ … However: I need it to be clamped so it only happens for diagonals and that backward diagonals are inverse so that the character keeps facing forwards

UPDATE 2

I fixed smooth rotation with my own script as well, much smoother now, see pic below. But again, my problem is to limit it to the diagonals and get the inverse of the direction of acceleration when moving backwards, can I clamp it somehow in this script? And make some check so that it rotates inversely when moving backwards on diagonals?