So I’ve been looking around for this one awhile now, and finally decided to just ask.
I want to drive some animations using the characters rotation, specifically this is for a “plant and turn” animation. I want to hook up a float that receives a characters local rotation, if it’s walking straight, that value would be 0, if it turns and starts walking to one side, that value would be +/- 90, and if it turns and starts walking in the opposite direction, the value would be 180. This value should also gradually reset back to 0.
I can’t for the life of me figure out how to get things hooked up so if anybody could help that would be super, I’m also open to alternative methods to achieve a plant and turn style animation.
EDIT: So I’ve deduced that if I take the characters world orientation and subtract a variable (local rotation), then plug that value back into the local rotation, I get the value I’m looking for. If I turn the character to 180 degrees, it would be 180 - 0 = 180. This is then plugged into the local rotation variable, which is now 180. Then if I turn the character to face 90 degrees, it would be 90 - 180 = - 90, which is the amount of degrees it rotated. However, this value keeps firing over and over again, so you get
90 - 180 = -90
-90 - 180 = 90
90 - 180 = -90,
and it keeps firing over and over, alternating between the two. What seems to me to be the simple answer is to only fire off the equation if world orientation doesn’t equal world orientation but I can’t for the life of me figure out how to do that. For clarification, if there is no change in direction, don’t fire off the equation.
Also again, if somebody knows of an easier way to go about this…
I basically just want to get the change in rotation, ie if it starts at 45 and ends at 50, thats a 5 degree change, and I want that value. Then I want that value to decrease back to 0 if there has been no changes in direction after x amount of time.
So you are going to want to Get Rotation, set a variable, and say 1 second later, Get Rotation again, but set a different variable. Then perform some math between the two variables to get the difference and use that difference to perhaps set a third variable.
Then you will want a separate process to count the time since the last change, which probably means you are going to want some delayed function to begin when you rotate and also simultaneously, you start counting time and if Time > X, it sets a bool to true which branches your delayed function to execute when it’s delay is complete. There are probably other ways to do that, but you should get the idea.
Then of course you need something that gradually reduces your variable to 0.
Ok, so I finally got this working, kinda. It works very well if the player is not moving when it starts firing, but if the player for example alternates between pressing and holding left and right, the values fail.