I’m trying to make a top-down character who will rotate and aim at the direction of the right-stick input.
I’m having two problems:
-
I’m trying to compare character facing and input, and turn the character to the lesser-of-the-two-angles towards the input. When I fire it up, it works at first, but then frequently gets stuck at cardinal points (0 and 180). The facing starts flipping between 0/1 or 179/180 every frame and so the character gets locked into that position. I’ve attached the script I’m using to control turning. Can someone see what I’m doing wrong (or give me a better way to do what I’m trying to do)?
-
I’m having problems with the character facing “skipping” past the input facing if I set the rotation speed too high. I assume this is related to frame-rate and the character jumping over several degrees per frame and missing the “match” with the facing. I converted facing and input to integers to get them to match at all, but if I go above 45-60 rotation speed (presumably whatever my frame-rate is), the character will frequently continue rotating, and do so until it happens to get a “match.” Is there a good way to prevent this from happening? And is there a way to make aiming more precise than 360 integers?
Thanks!