How to detect if a player has switched directions (approx 180)?

Hi.
I’ve made a simple 3rd person character controller that’s working pretty well, but I’ve reached a problem I’ve been trying to solve for months now and I was hoping somebody here would be able to help me.

I need to be able to tell when my character has switched directions to approximately the opposite direction.


I’ve sketched up a diagram to help explain the situation:

alt text

Ideal:
When suddenly switching direction, the character should slow to a stop, then continue in the new direction.

Current:
When suddenly switching direction, the character simply lerps rotation to the new direction, causing a “turning circle”

The best example I can come up with is Mario in Mario64:
If you run forwards, then attempt to move backwards, it’s detected as an opposite motion and Mario will skid to a stop, rotate to face the new direction and continue on his way.

Thanks for any help!

I think this question lacks some essential information. In trying to answer this I’m coming up with a dozen different things that need saying because not enough is stated here.

Does your character controller feature momentum? In other words, does the character accelerate to full walking speed over half a second, or instantly transition from stationary to full walking speed?

Does the effect you’re hoping to create involve an animated transition? If not, in what way shall you change direction except by rotating 180 degrees?

What should happen if the character is walking at full speed and the input suggests he move perpendicular (sudden change from forward to right/left input). Does that case require special treatment as well?

The answer to detecting a sudden change in input might involve simply comparing the forward direction to the input. If the dot product between the character’s forward and the input vector is close to negative one, the input constitutes a change sufficient to trigger this special action.

If the character is currently in motion forward when the abrupt input change occurs (and the character features momentum) then you blend into a skid-to-stop behavior, which blends seamlessly into an about-face animation. If the character is stationary, you’d blend directly from idle to about-face.