How to make character rotation snap to either 0,45,90,135... degrees

Jay1
Thu, 22 Apr 2021 18:20:54 +0000
Character & Animation

I am pretty new to Unreal. I am trying to use a set control rotation node to set my pawns rotation based on input from the “ASDW” keys. I used the “Rinterp to” to make the rotation smooth. I want the character to only lock onto the 0,45,90… increments of rotation and not be able to settle at say 37 degrees once the arrow keys are released. I tried this by creating an array of the absolute value of the desired increment angles minus the output from the “Rinterp to” node. I used index of the minimum value of the array to get the desired angle and set it as the input for the set control rotation node. This works, but only when the interp speed is set very low. When the interp speed is at 2, the character rotates and when the key is released snaps to the closest 45degree increment. As the interp speed goes up however, it no longer snaps to the closest increment. At 6, it will snap to all increments except the 180/-180 degree. If you release they keys when the character is facing the 180/-180 direction, it will snap to 135/-135. As the interp speed goes up, more increments fall off until at around interp speed value 20, the character will just snap to the 0 direction no matter where it faces when released. The “is arrow above zone” function returns true if one of the command keys is being pressed. Is there any simpler way to get the character to snap to the 45 degree increments? ( i have no idea if my blueprint is the most efficient or if there is a simple node that can accomplish this all that I missed) Is there a way to stop this from happening? Thanks!

6 posts - 3 participants