Character rotates on Y axis with Input System for some reason?

Okay so, I’ve decided to give Unity another go and with it, its “new” Input system. I’ve enjoyed it so far, but I’m having this odd issue where my character when pressing [Spacebar] or [Left Control] rotates facing up/down respectively and progresses into that direction.

I do have scripting that facilitates the character to rotate into the direction of movement and this functionality works well, but no matter what option I’ve tried I cannot stop the character from rotating awkwardly up/down.

I’ve tried rebuilding the Input mapping to 3D Vector, 2D Vector, not setting Up/Down or Forward/Back. I’ve tried a RigidBody3D and even with the RB3D restraining rotation on every axis didn’t work in any fashion. It’s been very odd/frustrating trying to stop this unwanted rotation for sure.

I’m providing a screenshot that will show the character at default (perpendicular to the ground - standing), then rotated facing upwards (parallel to the ground - laying down), the Input System’s current value mapping, and even the code provided in the script. If you know of any suggestions or solutions, I would be elated to know them and try them out!

Thank you in advance!

my guess would be your torotation

Yeah, but I can’t find a way to have it limited to ignore the Y axis movement though. I mean, I even tried to hardcode the IF/IF ELSE the toRotation is nested in to try and preemptively ignore that axis of movement.

well make sure the “to” has the same as the from ?

Just wanted to say that I’ve found my solution for this unintended/unwanted rotation. I created a 2nd Vector3 just for handling the rotation, then adjusted my code accordingly. So essentially there is 1 Vector3 for handling player translation and another Vector3 for handling player rotation. Most of the code stayed the same, but what did change was inside of my MovePlayer function that I’ll share here:

    void MovePlayer()
    {
        Vector3 direction = moveAction.ReadValue<Vector3>();
        direction.Normalize();
        transform.Translate(direction * speed * Time.deltaTime, Space.World);
        if (direction != Vector3.zero)
        {
            Debug.Log(direction);
            anim.SetFloat("moveSpeed", 1);

            // Create a direction vector that ignores the Y-axis for rotation (keeps the Y axis to 0)
            Vector3 directionForRotation = new Vector3(direction.x, 0, direction.z);

            // If there's movement on X or Z axes (ignoring Y-axis), rotate the character
            if (directionForRotation != Vector3.zero)
            {
                Quaternion toRotation = Quaternion.LookRotation(directionForRotation);
                transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rotationSpeed * Time.deltaTime);
            }
        }
        else
        {
            anim.SetFloat("moveSpeed", 0);
        }
    }