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

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!

Update: I changed the Rinterp to to Rinterp to constant. This allowed me to raise the interp speed high enough to look the way I wanted, however, when I unplugged my laptop (and switched from my RTX 2080 to the integrated intel graphics, it went back to needing very slow interp speeds. Is this that intensive a process? Is there a more efficient way to hit my goal, and is this going to cause issues if the game is being played on a less beefed up computer?

This arrangement will interp 45 degrees to the right on the player

Nearest45 is

EDIT: I don’t know exactly what you’ve done there, but interp is usually frame rate independent.

2 Likes

Thank you very much! I appreciate the time.

I can’t seem to find the “nearest” node?

It’s a function I made

image