Object Rotate

Hi, first of all, I’m not good at English, so please understand. I made a simple Character Rotate code in 3rd person, and it works well. But when character rotates from -90 to 90 degrees on the y-axis, the character rotates through backward. I want to make character rotate through forward in that case. How can I make it? I believe the first picture will be helpful. If you need anything else, feel free to ask me.
It’s the code.

    Vector3 GetMovePositionByCamera(Camera camera)
    {
        Vector3 inputMoveXZ = (camera.transform.forward * Input.GetAxis("Vertical")) + (camera.transform.right * Input.GetAxis("Horizontal"));
        inputMoveXZ.y = 0;
        inputMoveXZ = inputMoveXZ.normalized;
        return inputMoveXZ;
    }
    void Update()
    {
        Camera camera = Camera.main;
        Vector3 inputMoveXZ = GetMovePositionByCamera(camera);
        characterController.Move(inputMoveXZ * Time.deltaTime * moveSpeed);

        Quaternion targetRotation = Quaternion.LookRotation(inputMoveXZ);
        transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 5f * Time.deltaTime);
    }

And it’s my scene. I’m not good at drawing, so please understand, too :slight_smile:

I don’t know but something is telling me you need to try

Quaternion targetRotation = Quaternion.LookRotation(inputMoveXZ, Vector3.down);