Character 180 Degree Turn

Okay, so I’m working on a Super Mario 64 style 3D platforming game and I have run into a problem with my character controller. I am currently using mapping joystick input to a vector3 and using look at and translate to have my player go in that direction.
This works fine, but I am having trouble making a way for the code to know that the player did a full 180 degree turn instead of a slight one so it can play a different animation. I hope what I’m trying to do is clear, thank you for the help in advance.

Try this

void Update()
{
    float horizontal = Input.GetAxis("Horizontal");
  
    if(horizontal >= 0.1f)
    {
        //Moving right
    } else if(horizontal <= -0.1f)
    {
        //Moving left
    } else {
        //Not moving
    }
}

I appreciate the response, but that’s not what I meant. I need to be able to detect when the player turns around quickly no matter what their starting direction is.

You could try to check the angle between your previous direction and your new one, and if it’s bigger than X, it’s a quick turn.

float angle = Vector3.Angle(transform.forward, inputDirection);
if(angle > quickTurnAngle)
{
Debug.Log("QUICK TURN!");
}

Didn’t tested this code, but it’s and idea.

Hope it helps!

Thats exactly what @Icomstive code does. GetAxis returns a value from 1- to 1. -1 being turning fast to the left, 0 being not turning at all and +1 being turning fast to the right. You might have more control over the effect with a lerp though:

float horizontal = Input.GetAxisRaw("Horizontal");
turning = Mathf.Lerp(horizontal, turning, Time.deltaTime * turnSpeed);
if(turning > minTurnDetection) //turnRight
if(turning < -minTurnDetection) //turnLeft