Get Character Rotation Rate

Iv’e been making a third person locomotion system using UE4’s movement component. I need to get the current rate of rotation (yaw) for the character, and return it as a float so I can use it to drive my turn in place animations as well as my Run lean left/right animations. I know the movement component lets me get its velocity in the anim graph, but I haven’t figured out a way to get its rotation rate. I also know its a property that you can change in the character movement component details, but that’s about it. Is their a way I can do this either in my Character BP or my Animation BP? Any help would be appreciated! :smiley:

PS. I am an animator, not a programmer, and am still learning Blueprint :confused:

Thanks in advance!

In character BP " Get Mesh > Get Actor (World?) Rotation > Break Rot" - There’s your Yaw :wink:

Will this get me the speed of the rotation? I tried this but It doesnt seem to work. Im not concerned about what direction he is facing, but instead I need the speed of the rotation. So when he is turning, the float will give me the rate at which he is turning.

You could probably math-hack it by subtracting the current yaw from the last known yaw every tick.

Do you have any suggestions on how to do this? I’m no programmer. It makes sense but I’m not sure how to go about doing it.

My Guess

Set a Var - Current Yaw

When you go to check the next , check the current YAW against the “Current Yaw”

That way you will get a float of the difference.

** Look at this ***

fa2e9e0f906a153e12f42d2a337a67c0f1723c00.jpeg

Do not know how to use it. But may help

Got no idea what that does. I tried it but it didn’t work.

The easy way to do it: create a function. Call it, say “GetYawSnapshot”. Give it a single float output.

Inside of it, Get the actor rotation, break it, and take the Yaw value and feed it to the output.

What this will do is get, and return, the player yaw WHEN THIS FUNCTION WAS CALLED.

Okay, so now, go to your movement section of your graph to wherever it is the player’s rotation is getting updated. Before calling the movement command in your execution path, call this node. Then, AFTER the execution path applies movement/rotation/whatever, subtract the value from said node from the value of the actual Yaw of the actor’s rotation. If you print this to screen, you should see non-zero values when the character turns (if you see zero, it means you’re calling the Snapshot after the actor’s rotation has been updated, which is bad).

Ok Ill try this when I get home. If you have any free a screenshot will be helpful, but not needed. (Dont want to waste a veterans ) Youv’e done enough and I thank you for that :smiley:

When I get home I’ll set up a trial BP and see if I can’t get it working on my character… I realized after posting this that I don’t know when, exactly, Char Movement Component ticks the actor’s new rotation value; it might not be possible to use a “snapshot” node since it’s possible that the CMC does of its updates before any nodes in the BP graph even fire.

If that’s the case you’ll want to use a float var to store the value temporarily each tick, I’ll show you how, but I need to see.

I couldn’t get this method to work…not sure if I did anything wrong. it was giving me was the direction I was facing. Also, In my character BP I switch back and forth between facing the camera direction and orienting the capsule to face direction of movement. (I have “Use Pawn Control Rotation” checked in my camera settings, and that gets overridden based on if I’m using “Orient Rotation to Movement” which is controlled in my character BP.) This allows me to either run in directions (Standard third person movement) Or move in directions while facing away from the camera (Strafing). So I think in order to get the same results of capsule rotation speed regardless of what movement mode my character is in, I have to check its current world rotation, and compare it to the previous world rotation, and find the difference…or something like t

Yeah, do exactly that. This method is more complicated but will work regardless of how or when you drive your character capsule.

  1. New Float Var “LastKnownYaw”, New Float Var “YawDelta”.
  2. Get Actor World Rotation > Break
  3. (Yaw of GAWR) - (LastKnownYaw) > Set this value to YawDelta
  4. GAWR > Break > Set yaw value to LastKnownYaw.

Do this every Tick.

By setting LastKnownYaw AFTER calculating YawDelta (i.e. change in Yaw, you would then multiply this by your actor’s Delta seconds to get the Yaw Delta per second, or rotation rate), you guarantee that LastKnownYaw is always showing the Yaw value from LAST frame when you call it (then setting it with this frame’s value so that next frame it will have that data for the math again).

The only thing you may need to do is use your Construction Script to set the value of LastKnownYaw to whatever the actor’s initial Yaw is, so that the first frame of play doesn’t give weird results if the actor’s starting yaw is way far away from 0.

Ok…I thought I did what you said, but its not getting it. Ive got the first 4 steps working, then i subtract LastKnownYaw from YawDelta to get the change in yaw, then multiply it by Delta seconds to get rotation rate?

Wait! I read that wrong…I think iv’e got it!

Is this it?

You MAY have to DIVIDE by Delta seconds, actually… And you may have to divide Delta Seconds by IT. Try it 3 ways and see which returns sane results; I’m not entirely certain.

EDIT: yep, the pic looks right! Though that will only show how many degrees the yaw changed each frame, which isn’t strictly the same thing as the rate of change (which is per second).

Ok…Good news is it works, bad news is its too sensitive. I have a blendspace set up with walking, running, and leaning for turning. The rotation rate controls the amount of lean, but the values are too sensitive, and jitter a bit. Making the animations jitter alot. The values also go from say 6 to 0 instantaneously, when the capsule stops rotating. Is there a way to put a dampening system on it, so I get cleaner values, and maybe somehow make them blend from one to the other smoothly? I know this is alot to ask, but Im lost without this beautiful forum.

You should probably put the dampening on the Blendspace itself, using a “Target interpolation rate” setting inside the blendspace for that axis.

You CAN apply the damping directly to the variable using an FInterpTo node but it’s more complicated to set up than the sample interpolation smoothing in the Blendspace directly

EDIT: also, make sure you’re properly applying Delta Seconds to that DeltaYaw variable! Delta Seconds is the elapsed since last frame, and you know the rotation rate since last frame… If you know Seconds / frame and Yaw / frame, and you want Yaw / Seconds, you would divide the value you feed DeltaYaw by Delta Seconds before setting it. This will produce a much smaller value which should also be far more consistent from frame to frame.

That doesn’t mean you don’t want to interpolate, but if you see a lot of jittering delta compensation is like a magic bullet.

So I divided the value by delta seconds, and the value got much bigger, so i switched It, and now its smaller However, every second that my character is rotating at a constant speed, the value changes, than goes back to what it was. (It sort of flickers). I also frequently get extremely large values now as well. ones that go from the thousandths, to the thousands. Did I do something wrong? I think I’m applying delta seconds like I should be. I still need to interpolate but the rotation rate values haven’t gotten any better.

EDIT: I just figured out that the flicker in the rotation rate happens whenever I rotate past the world rotation of 180. It jumps to another value for an instant. I am still unsure about why the large values happen, although they usually happen when I use the mouse to rotate, and rotate just a little back and forth.