# How am I supposed to get the delta rotation through a period?

What I wanna achieve is to play some effect when the character make a sudden rotate (e.g. it turns 90 degrees in 1 sec), but I get stuck on how to store the rotation 1 sec ago and compare it to current one. 'Cause I may check the rotation every tick, the value will get renewed even if I store it in a local variable before I get the rotation 1 sec later. The character is controlled by player so I won’t be able to predict the rotation next sec.

Maybe it’s a stupid question but I just cannot figure it out… Lots of thanks if anyone can help.

In the tick push in a list a entry containing the rotation and the game time. And pop every entry too old.
Find the entry corresponding a the current gametime - 1 and test it.

Hi PhoenixThrough,

There’s a few way to deal with this but they all start from the same principle

Start off by storing the rotation in an array. Limit the number of element in the array so it does not grow indefinitely.

Then you can look at the first and last element and check the delta, this will give you to final rotation between then and now ignoring all the rotation in between. Just trigger the sound if the (absolute) difference between the first and last element is greater than “DeltaSound”. It’s often a good starting point and could be good enough.

Another way using the same array is to check for the min and max rotation in it and create a sounds when the the difference between min and max is greater than “DeltaSound”. This one is a lot more computationally heavy since you need to iterate through the array at least once per tick (maybe twice if you loop once for min and once for max)

Hope this helps

Cheers,

• Marc

I would do something similar to your second suggestion, checking the min and max. Instead of storing every value though, just store the largest and smallest. Then you can check on tick whether the current is less than min or greater than max, and replace the value if it is. That way you are only checking two values per tick, rather than a (potentially) large array.

So here’s my final solution… didn’t expect it to be this complex (I became too rely on Unreal and thought there would be some function to make things easier :P) This is a test BP so I only let it print “Hello” when there’s a sudden rotate.
Hope this will help someone.

I would follow your first way since there doesn’t supposed to be some wild rotate for my character like change to 90 degrees and back to 0 in a second (the input scale won’t allow it to do that). This really led me out, thanks!