Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug Subway surfer/ Character's rotation problem with CharacterController

Discussion in 'Physics' started by juanchocoreano, Mar 23, 2023.

  1. juanchocoreano


    Oct 21, 2021
    Hi! I am trying to make a game like subway surfers.

    I attached character controller. I created following script to move left & right.

    if (SwipeRIght)
    if (m_side == SIDE.Mid)
    NewXPos = XValue;
    m_side = SIDE.Right;
    else if (m_side == SIDE.Left)
    NewXPos = 0;
    m_side = SIDE.Mid;
    x = Mathf.Lerp(x, NewXPos, Time.deltaTime * speedDodge);
    m_characterController.Move((x - transform.position.x) * Vector3.right);

    The movement between 3 lanes works fine.

    But I have rotation problem with the character.
    When the running animation is activatin Position is moving by amination movement.
    It's not bad. However when moving "dodgeLeft" or "dodgeRight" is activated it's rotation keeps changing.
    So after few lane changes, it's y Y rotation is changed.

    seems like unlike Rigidbody, the character controller can't fix rotations.

    Anyone can fix this problem? or Do I need to change it to rigidbody?