move_toward, rotation and radians

So, I'm trying to rotate the player as they turn left and right in a top down view. The rotation works correctly when moving right, but fails going left.

Here's the code that handles the rotation

rotation = move_toward(rotation, PI / 12 * direction.x, PI / 2 * direction.x * delta)

The numerical values look right, giving me 0.261 rads going right and -0.261 rads going left ... but the rotation going left continues to go clockwise and stops just before a full 180.

Is there some quirk with rotation that I'm missing? My rubber ducks have remained silent.

11 points · 3 comments · view on lemmy.world

3 Comments

surlybaer@lemmy.world · 11 pts · 2y (2 replies)

Took a walk and figured out my issue. I shouldn't have used direction.x in the increments argument. move_toward figures that out for you.

chickenf622@sh.itjust.works · 10 pts · 2y (1 reply)

Way to not just say "nevermind fixed it"

noproblemmy@programming.dev · 4 pts · 2y

It has always sounded to me that that line is from people annoyed because they didn't get an answer. And I don't believe they figured anything out.