Find out whether the bot is rotating left or right

Hello. I have a bot that periodically turns towards the player. I don’t know how to find out whether it turns left or right, I need this to attach the necessary animations to it. I know how you can find out which direction the player is turning based on their “Input Axis” parameter, but this doesn’t work with a bot anymore.

The most logical thing to do is to set the flag at the moment when you directly rotate the bot. If this is not possible, then you need to compare the bot’s rotation from the previous frame with the current one, and accordingly, if the angle is greater/less, then the rotation will be left/right (or vice versa).

By the way, I also thought about this, but I thought that maybe there were other ways.

Can you tell me which function can be used to find the exact target, it just shows from -180 to 180 degrees and the transition from positive to negative breaks everything

You just need to consider this as an exception.
If the previous value was close to 180 (-180), and then changed sign - then the transition has occurred and the actual change in value in the other direction should be interpreted in the opposite way.

It will indeed break if you turn more than 360 degrees in one frame, but I don’t think the bot should do that. :sweat_smile:

1 Like

That’s it, I figured it out, this post with the scalar product helped. Detect when a character is turning left or right? - #9 by anonymous_user_af3bcfeb1

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.