[Solved] Rotate towards agnle in compass application problem

Hello all.

I’m trying to make a small compass app that has a needle sprite which moves similar to a compass needle. I am using “rotate towards angle” action with an angular speed of 20 in order to rotate the needle sprite to angle degrees between 0 and 359. Even though the app works for the most part I noticed than when the needle is already rotated at around 350 degrees and then I need to move it to e.g. 10 degrees then instead of moving in a clockwise motion it goes from 350 to 10 in a anti-clockwise motion, which messes up the experience.

I can bypass this behavior by changing the angular speed to 0, but the experience it’s also messed up, since a compass doesn’t turn that fast/

Any ideas on how I could fix that?

Hi @steliosm

I haven’t tried this but a possible solution would be:

if current angle > target angle   →   angle of needle: subtract 360
                                      rotate towards target angle

I don’t really think your example works. I tried playing with it using current angle = 350 and target angle = 10.

Sorry guys, my bad. I was testing with a wrong version of the code. “Rotate towards angle” action works fine, the “tween object angle” action doesn’t work as I would like to.

Yes, after I tried it, “rotate towards angle” always finds the shortest way to rotate to the target angle. Tween and lerp depend on the values if higher or lower.

1 Like