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

It’s a function I made

image